不能将Swing组件添加到多个容器中? [英] Can't a Swing component be added to multiple containers?

查看:471
本文介绍了不能将Swing组件添加到多个容器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试(测试其他内容)将一个 JButton 引用添加到两个 JPanels 中进行测试,它从添加到的第一个面板中消失了!

I'm trying (testing something else) to add one JButton reference into two JPanels to test it, and it disappears from the first panel it was added to!

那么,不能将Swing组件添加到多个容器中吗?

So, can't a Swing component be added to multiple containers?

提前谢谢。

推荐答案

来自: http://download.oracle.com/javase/tutorial/uiswing/components/toplevel.html


每个GUI组件只能包含
一次。如果某个组件已经是一个容器中的
,并且您尝试将
添加到另一个容器,则组件
将从第一个
容器中删除,然后添加到
秒。

Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the first container and then added to the second.

这篇关于不能将Swing组件添加到多个容器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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