Question subject: selection of checkbox in buttongroup in netbeans
Posted: Thu Jul 30, 2009 4:46 pm
Joined: Wed Jul 15, 2009 8:39 am Posts: 21 Has thanked: 0 time Have thanks: 0 time
Hi everybody
I have created a set of checkbox that i set the property "buttongroup" the same for all (i created a buttongroup) .I work with netbeans 6.5.1 so i used the palette to make this. I want to get the string of the selected checkbox . the problem that i cant't access to initcomponents () the method where the components are instancied. If i used :
Code:
buttonGroup1.getSelection().getClass().getName()
I get errors
How i can get the selected item. Please i need a help
msi_333
Question subject: Re: selection of checkbox in buttongroup in netbeans
Posted: Fri Jul 31, 2009 1:03 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 57 time
you can use :
Code:
buttonGroup.getSelection().getSelectedObjects()
or another way of thinking is :
Code:
orderButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String entree = buttonGroup.getSelection().getActionCommand(); System.out.println(entree + " sandwich"); Component[] components = condimentsPanel.getComponents(); for (Component c : components) { JCheckBox cb = (JCheckBox) c; if (cb.isSelected()) System.out.println("With " + cb.getText()); } } });
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )