您还可以使用itemListener的itemStateChanged方法,如下所示:
JToggleButton jtb = new JToggleButton("Press Me");jtb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { if(ev.getStateChange()==ItemEvent.SELECTED){ System.out.println("button is selected"); } else if(ev.getStateChange()==ItemEvent.DESELECTED){ System.out.println("button is not selected"); } }});
并且您想知道
jtb后者使用
isSelected()方法的状态
System.out.println(jtb.isSelected());if(jtb.isSelected()){ System.out.println("button is selected");} else { System.out.println("button is not selected");}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)