• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Adding elements to a JList dynamically  RSS feed

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am adding elements to a JList dynamically. When I click a button,
the element is nicely adding to the end of the JList. The JList elememts
should adhere to MouseEvent or ListSelectionEvent (I chose MouseEvent).
When I launch the application for the first time the JList adheres to
MouseEvents, but after adding elements dynamically, the JList doesn't
adheres to MouseEvents.

The code that adds elements dynamically to the JList
bsave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
defaultlistModel.addElement(date);
}
});

The code that adheres to MouseEvent
myJlist.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
if(me.getClickCount() == 1) {
String s = (String)myJlist.getSelectedValue();
ta.setText(" ");
String date = (String)myJlist.getSelectedValue();
}
}
});

How can I solve this problem?
Advance thanks.
 
Author
Posts: 965
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Giritharan Thavalingam:
When I launch the application for the first time the JList adheres to
MouseEvents, but after adding elements dynamically, the JList doesn't
adheres to MouseEvents.



Your code looks ok to me, and I can't see how adding elements
to the list model could be affecting the mouse listener stuff.

It looks like all your mouse listener does is clear a text
component. Are you sure that's not happening when the user
clicks on the JList (even after elements have been added)?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!