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 .addElement() causes ListSelectionEvent? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark ".addElement() causes ListSelectionEvent?" Watch ".addElement() causes ListSelectionEvent?" New topic
Author

.addElement() causes ListSelectionEvent?

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
In my program, it seems that sometimes the addElement(Object element) method in the DefaultListModel of my JTable causes a ListSelectionEvent. That seems strange to me because ListSelectionEvent objects are usually caused by changes in the selection of a JTable. Just adding elements to the end of a DefaultListModel should not change the selection(s) of a JTable, I think.
Are there any situations in which adding an element to the end of a DefaultListModel would cause a ListSelectionEvent? What kind of situation? Why? (there are some things in life that don't have a reason, but if there is a reason you can think of, please tell me) What is a good way to prevent a ListSelectionEvent?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
I've never seen this happen. Post your SSCCE that demonstrates the problem.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

Kevin Tysen wrote:In my program, it seems that sometimes the addElement(Object element) method in the DefaultListModel of my JTable causes a ......

DefaultListModel ? For JTable?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
Here is an abbreviated version of the program.



Start up the program and click the words "click me". That will generate a ListSelectionEvent. Then, click the button "Take Out". That will generate another ListSelectionEvent, because the selected item is deleted. Then, click the "Append" button. That generates another ListSelectionEvent, but I don't know why. Before the button is clicked, and after the button is clicked, nothing is selected, so there should be no change in the selection which would generate an event.
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
In my original message I made a mistake. It's not JTable, it's JList.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: .addElement() causes ListSelectionEvent?