Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取分配给JComponent的名称_Java_Swing - Fatal编程技术网

Java 获取分配给JComponent的名称

Java 获取分配给JComponent的名称,java,swing,Java,Swing,我有一个arrayList,数组中的名称数量根据其使用方式而有所不同。我为其中一个名为arrayList的函数创建JRadioButtons,如: for(int i = 0; i < m_fixtures.size(); i++){ panel.add(new JRadioButton(m_fixtures.get(i))); } for(int i=0;i

我有一个arrayList,数组中的名称数量根据其使用方式而有所不同。我为其中一个名为arrayList的函数创建JRadioButtons,如:

for(int i = 0; i < m_fixtures.size(); i++){
    panel.add(new JRadioButton(m_fixtures.get(i)));
}
for(int i=0;i
有没有什么方法可以检查为JRadioButton分配了什么名称,因为我想按照


获取选定的Jradiobuttons“label”并向该数据添加do,但我不知道如何获取分配给它的“label”。

您是否尝试调用getText()?查看此处:@RubioRic但按钮没有特定标识符,例如JRadioButton button=new JRadioButton(“文本”);我不知道如何在没有实例名的butotn上调用.getText()。@PigeMilkStores也许我的答案有助于您尝试调用getText()?请看这里:@RubioRic但按钮没有特定标识符,例如JRadioButton=new JRadioButton(“文本”);我不知道如何在没有实例名的butotn上调用.getText()。@PigeMilkStores也许我的答案有帮助
   Component[] components = panel.getComponents();

   for (Component singleComponent : components) {
       if (singleComponent instanceof JRadioButton) {
           JRadioButton jrb = (JRadioButton) singleComponent;
           // println or whatever you want
           System.out.println(jrb.getText());
       }
   }