Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange behavior - JTable in an OSGi application  RSS feed

 
olze oli
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have no idea how to describe what is going on... so i made a little video, hope this is ok
some forewords:
the application uses the eventadmin class from apache felix. when the "go" button gets hit, an event is fired to all listening plugins (at the moment only the jamendo plugin).
the plugin returns a list of songs and those should be added in the gui.
i added 2 rows in the jtable, the first starting with {"hello world", "asdf", "asdf", "asdf", null} and the next with {246, 357, "asdf", "asdf", null} hardcoded (created with netbeans)
after everything is set up in the BrowserFrame's (this is the JFrame containing the JTable) constructor i start a thread that inserts some values for testing purpose (thats the code you can see in that video)
this works as expected as long as i dont resize the frame...

when the "go" button is hit, one result is returned by the plugin and added to the jtable which works as expected, but when i click on the table it starts with that behavior, when i resize the frame the jtable gets messed up...

the link to the video:
http://www.youtube.com/watch?v=tzbPyGhiwzU

thanks
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using SwingUtilities.invokeLater in the constructor; are you also using it with the code that's executed when you press the "go" button? Around 0:28 your table's values change when you click on them. This kind of behaviour is often caused by a failure to fire the right events. Since you're using DefaultTableModel that's most likely not the cause, so perhaps a threading issue is.
 
olze oli
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

thanks for your fast reply.

The code is available at https://svn.origo.ethz.ch/soundbox/SoundBox-BrowserGUI/src/main/java/org/dyndns/soundi/soundbox/core/gui/BrowserFrame.java
It is the only thread in that class. I fire an event on line 541:


when i run the application and the gui is displayed (and 10 entries are added) i get the same behavior when i resize the window even without clicking the go button - but i did not change anything, just resized the frame
thanks in advance for your help

edit: it is not the only thread, it should be the only thread ;)
there is also the pluginListener which should be in another class - i will test if it works when i comment it out
- i commented out the pluginListener(); call inside the constructor... it does not solve the problem
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not related, but your handleEvent method has a bug.
With the removal you are actually skipping half of the rows. You delete row 0. Old row 1 becomes row 0 and old row 2 becomes row 1. You then delete row 1. Row 0 is still there. Simply use model.setRowCount(0) instead.
You don't need to set the table model to the exact same table model.
You add only one song because you return after that.

The rest of your code does show a thread related bug. pluginListener creates a new thread that calls addPortalToGui. In there you modify the GUI directly. That means you are accessing the GUI from multiple threads.

However, the resizing is definitely not caused by that. I stripped out a lot of your code to allow it to compile, and the problem is still there. When I resize the window I notice that the user interface appears to be duplicated - two tables, two sets of buttons, etc. The second one is initially displayed below the first one. A simple System.out.println from initComponents showed that the method is actually called twice. The reason is simple - you call it from the constructor, then again from the constructor through display. Remove the entire initialization from that method.
 
olze oli
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot! its working
i forgot to use the initialized field in the constructor
i changed it to:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!