2 years ago

#23395

test-img

Pompompurin

Concurrency problem in updating Jtable/Jframes?

I will try to describe the problem as accurately as possible, since this is a legacy project from someone else that I am trying to fix (to the best of my abilities).I cannot build an accurate working example due to the way this project is done. The way this program was built is wrong in many places so just pinpointing the problem would help me immensely.

There is a Jframe with a menu bar and table. The frame switches between Tables based on which option you click within the menu bar. Here's the problem: When updating the table, the first table seems to be fine, but the other ones fails to update its view properly if something is changed (specifically, it doesn't update upon deletion, but insertion seems fine). This is how the main table is made:

public void start(){
 mainTable=new Jtable(model){
  public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
   /* tons of styling here */
  };
}
 /* a bit more styling? */
 renderSecondTable();
 renderThirdTable();

}

I apologize for this ugly code, the codebase itself is even worse. Does rendering other tables by calling a method within this "start()" function lead to concurrency problems? Which is why updating the view is problematic? Extra information that might help:

  • each table has a seperate Frame, so there is a main frame and then a smaller frame that displays the tables
  • buttons for each table (delete, update etc.) are also added in by calling in extra methods like RenderButtonsForTable1()
  • They are all AbstractTableModel
  • calling FireTableDataChanged() or other similar functions do not seem to do work for non-main-tables
  • revalidate and repaint also doesn't work

The table does NOT use removeRow or fireTableRowsDeleted to remove the rows, there are seperate functions that do this with object streams (I don't quite understand this yet). The view seems to update automatically for the main table just fine.

Again I apologize if this is extremely confusing and ugly, the original creator didn't seem to understand what he was doing either :/

Edit: More clarification!

  • It seems that it does in fact only have one MAIN frame, and this frame swaps out multiple Jpanels (each with a different Table). Within each Panel there is also a scrollpane
  • Deleting from the main Panel causes no problems, but deleting entries from other Panels require the Frame to be reopened or else the entry just stays there (also breaks the frame/panel completely if you empty the entire table)
  • The entry is properly disposed of in the backend (as far as I can tell)
  • any insert/delete is done through an action listener for the corresponding button
  • Each table has a seperate Tablemodel (all extends AbstractTableModel) with its seperate functions that all do the same thing
  • Table is filled with data read from a database
  • all tables are made in the same fashion as the main one above with prepareRenderer

I also drew up a vague diagram of how the Jframe looks: JframeExample

java

swing

jframe

jtable

jscrollpane

0 Answers

Your Answer

Accepted video resources