开发者

Add a Component to two different JTabbedPanes

开发者 https://www.devze.com 2022-12-29 01:58 出处:网络
I have a LinkedList of Components, each of which I would like to add into two different JTabbedPanes. For some reason, Swing is only letting me put each component into one or the other. The code I\'m

I have a LinkedList of Components, each of which I would like to add into two different JTabbedPanes. For some reason, Swing is only letting me put each component into one or the other. The code I'm using is the following:

/* The two tab panes */
JTabbedPane leftTabs = new JTabbedPane();
JTabbedPane rightTabs = new JTabbedPane();

for (int i=0; i<tabPanes.size(); i++) {
    rightTabs.add(tabPanes.get(i));
    leftTabs.add(tabPanes.get(i));
}
开发者_高级运维

Whichever add call I put last is the one that works; if I add to leftTabs last, then rightTabs ends up empty, and vice-versa.

Any ideas on how to get this working? Thanks!


A component can only have a single parent, so you can't add it to two different tabs.

However the model of the component can be shared. For example:

JTextField textField1 = new JTextField();
JTextField textField2 = new JTextField();
textField2.setDocument( textField1.getDocument() );

So somehow you to figure out how to share models, not the components.

0

精彩评论

暂无评论...
验证码 换一张
取 消