Java卡布局。在多卡单组分 [英] Java Card Layout. One component in multiple cards

查看:274
本文介绍了Java卡布局。在多卡单组分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在一个组件(如的JLabel )在使用多卡 CardLayout

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?

推荐答案

您是正确的,它只能出现在它被添加到最后一张牌,但无关与 CardLayout ,即是与事实做每个组件只能在一个父。

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.

从的Javadoc <一个href=\"http://docs.oracle.com/javase/7/docs/api/java/awt/Container.html#addImpl%28java.awt.Component,%20java.lang.Object,%20int%29\"><$c$c>java.awt.Container.addImpl(Component补偿,对象的限制,INT指数) :

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.

这篇关于Java卡布局。在多卡单组分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆