Java Card Layout. One component in multiple cards

天大地大妈咪最大 提交于 2019-12-11 01:28:36

问题


Can one component (e.g. a JLabel) be in multiple cards using CardLayout?

Currently it seems that the component appears only at the last card it was added to.

If there is a way to do this, should I? Is it bad practice? Or is there some alternative?


回答1:


You are correct that it only appears in the "last card it was added to", but that has nothing to do with CardLayout, that has to do with the fact each component can only be in one parent.

From the Javadoc for java.awt.Container.addImpl(Component comp, Object constraints, int index):

If the component is not an ancestor of this container and has a non-null parent, it is removed from its current parent before it is added to this container.



来源:https://stackoverflow.com/questions/23519848/java-card-layout-one-component-in-multiple-cards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!