Tag: jcomponent

如何获取JFrame中的所有元素?

我有这个代码来获取我需要的所有元素并进行一些处理。 问题是我需要指定每个面板来获取其中的元素。 for (Component c : panCrawling.getComponents()) { //processing } for (Component c : panFile.getComponents()) { //processing } for (Component c : panThread.getComponents()) { //processing } for (Component c : panLog.getComponents()) { //processing } //continue to all panels 我想做这样的事情,并获得所有的元素,而不需要specefy所有的面板名称。 我是怎么做到的 下面的代码没有获得所有元素。 for (Component c : this.getComponents()) { //processing }

不能将Swing组件添加到多个容器中?

我正在尝试(测试别的东西)将一个JButton引用添加到两个JPanels进行测试,它从添加到的第一个面板中消失了! 那么,不能将Swing组件添加到多个容器中吗? 先谢谢你。