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

查看:39
本文介绍了一个 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天全站免登陆