Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:02:20+00:00 2026-06-11T06:02:20+00:00

Basically, my project is to create a simple library system where any given user

  • 0

Basically, my project is to create a simple library system where any given user can have up to three books out at a time. I’m doing it with BreezySwing (because I’m required to) and using a JList to list the currently taken out books.

To return a book, the user clicks on the book to return in the list, and clicks the “Return” button. However, I can’t figure out how to get the JList working properly.

How to add new information to the list?

Here is the code I have so far:

import java.util.*;
import javax.swing.*;
import BreezySwing.*;

public class ClientGUI extends GBFrame {
    private JButton returnBook, takeOutBook;
    private JLabel title, author;
    private JTextField titleInput, authorInput;
    private int bookCount = 0;
    DefaultListModel books = new DefaultListModel();
    private JList booksOut = new JList(books);

    public ClientGUI(){
        title = addLabel("Title: ",1,1,1,1);
        author = addLabel("Author: ",2,1,1,1);
        titleInput = addTextField("",1,2,2,1);
        authorInput = addTextField("",2,2,2,1);
        returnBook = addButton("Return",3,1,1,1);
        takeOutBook = addButton("Take Out",3,2,1,1);
        booksOut = addList(4,1,2,1);
        returnBook.setEnabled(false);
        books.addElement("Book - Author");
    }

    public void buttonClicked(JButton buttonObj){
        if(buttonObj == takeOutBook){
            if(bookCount < 3){
                String titleAdd = titleInput.getText();
                String authorAdd = authorInput.getText();
                books.addElement(titleAdd + "By: " + authorAdd);
                bookCount++;

                if(bookCount == 0){
                    takeOutBook.setEnabled(true);
                    returnBook.setEnabled(false);
                } else if(bookCount == 3){
                    takeOutBook.setEnabled(false);
                    returnBook.setEnabled(true);
                } else {
                    takeOutBook.setEnabled(true);
                    returnBook.setEnabled(true);
                }
            } else if(bookCount == 3){
                JOptionPane.showMessageDialog(null, "Please return a book first", "Invalid Choice", JOptionPane.INFORMATION_MESSAGE);
            }
        } else if(buttonObj == returnBook){
            //int n = (Integer) books.getSelectedValue();
            //books.remove(n);
            bookCount--;
            if(bookCount == 0){
                takeOutBook.setEnabled(true);
                returnBook.setEnabled(false);
            } else if(bookCount == 3){
                takeOutBook.setEnabled(false);
                returnBook.setEnabled(true);
            } else {
                takeOutBook.setEnabled(true);
                returnBook.setEnabled(true);
            }
        }
    }

    public static void main(String args[]){
        ClientGUI GUI = new ClientGUI();
        GUI.setSize(300,275);
        GUI.setTitle("Library");
        GUI.setVisible(true);
     }
}

Basically, what I need to do is get the JList working properly. The rest I can finish. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:02:21+00:00Added an answer on June 11, 2026 at 6:02 am

    Try DefaultListModel.addElement

    It will fire update events for the list to respond to

    UPDATE

    Without knowing how BreezySwing works, I’d be focusing on this line…

    booksOut = addList(4, 1, 2, 1);
    

    Given what I believe the other lines in the code are doing, this would appear to “create” a new Jlist and return it (applying the layout).

    This means that the model been used by booksOut is no longer the books model.

    Try adding

    booksOut.setModel(books);
    

    After the addList line and see if that helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

does anyone have any suggestions for what I can do to try and create
I've got simple java-based ppt->swf sub-project that basically works. The open source software out
My project is basically like a Reddit feed that updates in real-time. I'm trying
In my domain I have something called Project which basically holds a lot of
Basically on GunChester my project I have an few pixel wide gap between #login_top
Basically I have a series of projects displayed on the page. Each project consists
I wanted to create a simple paginated search for my project. I'm having trouble
I created a very simple C++ library in xcode, it was basically: //Numbers.h class
I have a simple project created in Qt Creator (installed using Qt SDK 1.1.4).
I've inherited a project that uses Active Reports. I'm required to basically create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.