PDA

View Full Version : disabling product checkboxe



Ken Alverson
03-14-2003, 10:22 AM
We have a need to disable the first product checkbox because the product should alway be installed (customer should not be able to uncheck the checkbox). The following custom code works only after I click the next button after the panel is initiallly displayed. It there a way to get it to be disabled when the panel first appears?

/**
*
* <P>This class finds and disables the first checkbox in the Product Selection
* panel.
*/
public class HelpSystemsProductPanel extends ProductPanel
{
public boolean queryEnter(WizardBeanEvent event){

super.queryExit(event);
findComponets();
return true;
}

public boolean queryExit(WizardBeanEvent event){

super.queryExit(event);
findComponets();
return true;
}

protected void findComponets() {

try {
Container container = null;
JCheckBox theEvilCheckbox = null;
WizardPanelImpl wizard = getWizardPanelImpl();
if (wizard instanceof SwingWizardPanelImpl) {
SwingWizardPanelImpl swingwizard = (SwingWizardPanelImpl) wizard;
Container parent = swingwizard.getParent();
while (parent.getParent() != null)
parent = parent.getParent();
Component[] children = parent.getComponents();
for (int i = 0; i < children.length; i++) {
Component child = children[i];
if (child instanceof Container) {
theEvilCheckbox = findCheckbox( (Container) child);
if (theEvilCheckbox != null) {
// we found it!!!
theEvilCheckbox.setEnabled(false);
}
}
} // end FOR - digging up the dirt
}
}
catch (Throwable ex) {
}
}

protected JCheckBox findCheckbox(Container container) {
if (container == null)
return null;
Component[] subchildren = container.getComponents();
for (int j=0; j < subchildren.length; j++) {
Component child = subchildren[j];
if (child instanceof JCheckBox)
return (JCheckBox) child;
if (child instanceof Container) {
JCheckBox cb = findCheckbox( (Container) child);
if (cb != null) {
return cb;
}
}
} // end FOR - looping through the container's childeren
// nope, no checkboxes here!
return null;
} // end METHOD - findCheckbox

// public static void main ( String[] arg) {}
}

joel100
03-20-2003, 12:20 PM
did you mean to have
super.queryExit(event);
in your queryEnter(...) function?

Ken Alverson
03-20-2003, 01:11 PM
Originally posted by joel100
did you mean to have
super.queryExit(event);
in your queryEnter(...) function?

Yes, thank you. I also added:

public boolean entered(WizardBeanEvent event){

super.entered(event);
findComponets();
return true;
}

it works now:)