• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

updating custom JList

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...

Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
add the new video to the list's listModel.

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

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic