I have a JTable called tableOne
.
I filled this table like this:
JTable tableOne = new JTable(contents, header);
//contents is a String[][] and header is a String[] defined above.
I also have a list of CustomObject
Objects. All these objects have a String[][] named customObjectContents
assigned to it. These 2D arrays are filled with data.
I now want to use the ListSelectionListener
to change the the displayed data in tableOne
to the contents of the individual object's customObjectsContents
.
How would you suggest I approach this. I cannot manipulate the variable tableOne
in the Listener since it is not final. (maybe I just need to declare it final, but then I cannot manipulate it anymore which seams paradox)
So I may need some other form of java technology I might not even heard about and I have no idea where to look.
In the end I want to use the objects variables to display them into the JTable
.
The solution was actually to create a new table model. Instead of filling the table in this way:
JTable tableOne = new JTable(contents, header);
I resorted to filling it in this way
DefaultTableModel model = new DefaultTableModel();
JTable tableOne = new JTable(model);
Other than the table itself, the model chan be changed in the listener. For my purpose of setting a new String[][] as content for the table, I used the following code:
model.setDataVector(customObject.contentsArray, header);
contentsArray is a String[][] stored in the object. Header is a general String[].
I hope this helps anyone who reads this post.