File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes updating custom JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "updating custom JList" Watch "updating custom JList" New topic

updating custom JList

Summer Laughlin

Joined: Apr 11, 2007
Posts: 1
Im sure this question has probably been asked before, but I cant find an answer that seems to help me, so maybe someone will answer it in a way that does.

Im creating a video store program for a class that I am taking. We just recently moved the program from being all text-based in a console window to using a swing gui. So far what we have is a JFrame that contains two items, a JList and a JButton. The JList contains a list of movies that are hard coded into a class that manages all of the videos. The button brings up a custom JDialog that contains text fields to allow the user to input values for a videos title and director, etc, add therefore add a video with these values to the Jlist. The Dialog also contains a button that, when pressed, uses the getText() method to feed the input values into set methods and the video is created without a problem. The button also sets the JDialog to visibility to false so that it adds the movie and closes, bringing the user back to the main window that contains the JList and JButton, as described before. I can print the video out to the console just fine, so I know that there is no problem in these steps.

The problem is that the list needs to be updated automatically when the JDialog is closed. Im not sure of the best way to do this, or even of a way that works to do this. I thought that maybe I needed to implement a ListListener of sorts, whether is be predefined or custom written, or maybe there was another way to do it, I dont know. I was hoping that someone would be able to give me (a relatively new coder) a few pointers...

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
add the new video to the list's listModel.

simple demo of adding (hard-coded, no dialog)

I agree. Here's the link:
subject: updating custom JList
It's not a secret anymore!