File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "updating custom JList" Watch "updating custom JList" New topic
Author

updating custom JList

Summer Laughlin
Greenhorn

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...

Thanks!
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: http://aspose.com/file-tools
 
subject: updating custom JList
 
Similar Threads
Populating JList in Parent window from Child window's save button
Data Xchange from JDialog to JTable using JButton
Won't repaint!
Keeping each ID constant
JList set element visible