Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating JList on GUI

Status
Not open for further replies.

brinker

Programmer
May 31, 2001
48
CA
Hi All,

I have a JFrame which contains a JList Object. I initialize the JList object normally using:

urlList = new javax.swing.JList(barstools);

However, I want to be able to add to the JList and Remove from it. There is an actionListener for a menubar item that deletes all the items from the JList:

JMenuItem newSelect=new JMenuItem("New List");
newSelect.setMnemonic('N');
newSelect.setToolTipText("Create a New URL List");
newSelect.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e)
{
System.out.println("4");
urlList.removeAll();
urlList.updateUI();
repaint();
}
}
);
menu.add(newSelect);

However, the GUI will not refresh. Does anybody have some ideas?

thanks

Brinker
 
O.K., I think that I've tried almost everything (from using paint, repaint, update, etc), but I still cannot get the GUI to update and display the correct JList. All of the elements appear to be gone from the list itself with the url.removeAll() command, but the displayed list is still the old one.
 
Swing works on the Model-View-Controller (MVC) pattern, but it also allows you to add to objects directly. Create the JList with a model and whenever you add/remove items from the model the changes will be reflected on the screen. Jeremy Nicholson, Director of a UK-based Java and Data Warehousing consultancy
 
Thanks for the help.

I figured out the DefaultListModel this morning while struggling with the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top