JTable and multiple JFrames
Hello all,
I created a program that produces a schedule and displays it in a JTable which is in a JScrollPane in my main GUI frame. Everything works fine and perfect, just as I intended.
However, I have also added an ENLARGE button to my GUI which simply creates a new JFrame, adds the JScrollPane container to it and sets the resizeable parameter of the newly created JFrame to true so that user can maximize the window making the schedule much more readable. However, the problem is that the original JScrollPane(with JTable) gets erased from my main GUI frame.
Any suggestions or ideas?
Thanks.
[629 byte] By [
WhiteTreea] at [2007-11-26 21:49:54]

# 1
Post a short compilable code. Cant make out what is wrong just from your description alone.
To me it seems like, you are using the same JTable/JScrollPane instance at two places. You cannot add the scrollpane/table to two containers and expect them to be displayed in both. if it is displayed in one, it will be removed from the other one.
# 2
A component can only have a single parent, so you can't add the scroll pane to another frame.
The solution is to create a new scrollpane and table and to share the TableModel with the TableModel with the new created table.
JTable larger = new JTable( originalTable.getModel() );
# 3
Yea, thats what I worried I had to do and thats what I had originally and it worked well but it just didn't feel right to have a lot of duplicated code since my original table has some listeners and a lot of formatting (i.e. highlighting and colors etc.). It just made sense to me to simply reference the already made table. But anyway, guess I'll have to go the long route. Thanks guys for your help :).