将组件添加到两个不同的 JTabbedPanes
我有一个 Components
的 LinkedList
,我想将每个组件添加到两个不同的 JTabbedPanes
中。由于某种原因,Swing 只允许我将每个组件放入其中一个组件中。我使用的代码如下:
/* 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));
}
无论我最后放置的哪个 add
调用都是有效的;如果我最后添加到 leftTabs
,则 rightTabs
最终为空,反之亦然。
关于如何让它发挥作用有什么想法吗?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个组件只能有一个父组件,因此您不能将其添加到两个不同的选项卡。
然而,组件的模型可以共享。例如:
所以你要弄清楚如何共享模型,而不是组件。
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:
So somehow you to figure out how to share models, not the components.