1

I am new to Java, so any help is greatly appreciated...Thanks in advance.

JFrame-1 is split with JTable and JEditorPane. I create a new JFrame-2 after some events that occur on JFRame-1. JFrame2 also has a JSplitPane implemented( with 2 JTables(1 & 2) and 1 JEditorPane). as soon as i copy the contents of JTabel from frame-1 to Jtabel2 in frame-2. the table disappears from the frame-1, How can i keep the contents of table in frame-1 as well as in frame-2. This is the code i used to split the panes for Frame-2, and during debugging this is where the table(m_clsJTable) from Frame-1 clears.

JSplitPane top = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(clsNewJTable), new JScrollPane(m_clsJTable)); 
        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, new JScrollPane(m_clsJEditorPane)); 
rkbdi
  • 21
  • 2

1 Answers1

2

You can't put the same components in two different containers. If you want two containers to have the same view of some data, then you should create a separate view class for each, and have them both share the same model.

MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66
  • +1 This related [example](http://stackoverflow.com/questions/2614457) also talks about how to synchronize scrolling. – trashgod Mar 24 '11 at 18:31
  • Now i understand why it was clearing out the table from Frame-1. To separate view class for each- can you please explain this or point me to something that refers to this. Thank you! – rkbdi Mar 25 '11 at 15:17
  • @trashgod: Sorry, my example has one model for each view. @rkbdi: I think it would work with just one model in both views. – Catalina Island Mar 25 '11 at 16:36
  • @MeBigFatGuy- I am using defaultTableModel to create the JTable in Frame-1. will i still be able to create separate view class for each table? can you give me an example of 2 components (JTable) sharing the same defaultTableModel. – rkbdi Mar 30 '11 at 18:51
  • I got the table in Frame-2. Thanks! – rkbdi Mar 31 '11 at 15:35