PDA

View Full Version : Menu with ButtonGroup



snpe
Dec 2nd, 2004, 04:12 AM
Hello,
I want create menu with a few JCheckBox members and only one selected (like ButtonGroup do)
How I can do it with TargetableActionCommand (menu have another item, too) ?


regards

Keith Donald
Dec 2nd, 2004, 07:38 AM
Snpe,

Take a look at an example of this in the application.setup license wizard support--the class is SetupLicenseWizardPage. In it, it creates an exclusive command group and generates radio buttons for the accept / do not accept commands. You can apply a siimiliar approach, only generate check boxes instead of radio buttons:



protected JComponent createControl() {
...

ToggleCommand acceptCommand = new ToggleCommand("acceptLicenseCommand") {
protected void onSelection() {
SetupLicenseWizardPage.this.setEnabled(true);
}
};

ToggleCommand doNotAcceptCommand = new ToggleCommand("doNotAcceptLicenseCommand") {
protected void onSelection() {
SetupLicenseWizardPage.this.setEnabled(false);
}
};
doNotAcceptCommand.setSelected(true);

CommandGroup.createExclusiveCommandGroup(new ToggleCommand[] { acceptCommand, doNotAcceptCommand });

GridBagLayoutBuilder formBuilder = new GridBagLayoutBuilder();
formBuilder.append(new JScrollPane(licenseTextPane), 1, 1, true, true);
formBuilder.nextLine();
// can say createCheckBox instead...
formBuilder.append(acceptCommand.createRadioButton ());
formBuilder.nextLine();
formBuilder.append(doNotAcceptCommand.createRadioB utton());
return formBuilder.getPanel();
}


Keith

snpe
Dec 2nd, 2004, 11:22 AM
It work fine.Thanks