setEnabled(false) for Checkbox using jdk 1.6 - non-clickable but not grayed out

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rrlveloso09
    New Member
    • Jan 2009
    • 3

    setEnabled(false) for Checkbox using jdk 1.6 - non-clickable but not grayed out

    ---code---
    if (readOnly) {
    //cb.disable();
    cb.setEnabled(f alse);
    }

    when lower versions of jdk is used (lower than 1.4), the disable() method is working properly (meaning the checkbox is graying out and becoming non-clickable), but when higher versions of jdk (1.6) is used to open the applet, the checkbox only becomes non-clickable. It is no longer becoming gray. I substituted the disable() method with setEnabled(fals e) but still it is not grayed out. Anybody knows how to gray out checkbox in jdk 1.6?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    That's strange; I use Java 1.6 (update 11) but those check boxes are greyed when disabled (indeed, use the setEnabled(fals e) call). Are you using another look and feel perhaps? Can you show a bit of relevant code? How do your radio buttons and toggle buttons behave?

    kind regards,

    Jos

    Comment

    • rrlveloso09
      New Member
      • Jan 2009
      • 3

      #3
      public void populateRadioBu ttons() {
      Enumeration e = widgets.element s();
      while (e.hasMoreEleme nts()) {
      prompt.removeWi dget((Component ) e.nextElement() );
      }
      widgets = new Vector();
      CheckboxGroup cbg = new CheckboxGroup() ;
      String[] choice;
      extractChoices( );
      e = choices.element s();
      Checkbox cb;
      while (e.hasMoreEleme nts()) {
      choice = (String[]) (e.nextElement( ));
      cb = new Checkbox();
      cb.setBackgroun d(prompt.style. backgroundColou r);
      cb.setCheckboxG roup(cbg);
      prompt.addWidge t(cb);
      if (readOnly) {
      //cb.disable();
      cb.setEnabled(f alse);
      }
      widgets.addElem ent(cb);
      }
      setValue(value) ;
      }

      public void setValue(String v) {
      switch (type) {
      case CHOICE_FIELD :
      selectedKey = v;
      // If only one radio button, select it...
      if (choiceLayout != null & choices.size() == 1) {
      ((Checkbox) widget()).setSt ate(true);
      } else {
      boolean found = false;
      for (int i = 0; i < choices.size(); i++) {
      if (choice(i)[0].equals(v)) {
      found = true;
      if (choiceLayout == null)
      ((Choice) widget()).selec t(i);
      else
      ((Checkbox) widgets.element At(i)).setState (true);
      }
      }
      if(!found) {
      for (int i = 0; i < choices.size(); i++) {
      if (choice(i)[1].equals(v)) {
      selectedKey = choice(i)[0];
      if (choiceLayout == null)
      ((Choice) widget()).selec t(i);
      else
      ((Checkbox) widgets.element At(i)).setState (true);
      }
      }
      }
      }
      break;
      }
      }
      I just updated w/ 1.6 update 11 but still it is not grayed out. I have 2 methods. First to be called is populateRadioBu ttons() which is where the checkbox is set to disabled. The next method setValue() sets the state of the checkboxes. Are there any methods that removes the gray function for the checkboxes? Or are there any ways to gray out checkboxes directly?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        You are using a Checbox; it is an AWT component; any reason why you don't use a JCheckbox; a Swing component? The two can't be easily mixed.

        kind regards,

        Jos

        Comment

        • rrlveloso09
          New Member
          • Jan 2009
          • 3

          #5
          Actually all components used (textbox, radio buttons, checkboxes, and the like) are AWT component so its hard to change the components into Swing. Do you think using VisualAge Smalltalk / VisualAge Java can cause the checkbox not to be grayed out? Or is it because of the AWT component I'm currently using?

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            I don't know what's happening on your computer but the following test snippet runs fine on my machine:

            Code:
            import java.awt.Checkbox;
            import java.awt.Frame;
            
            class Test {
            
            	public static void main (String[] args) {
            
            		Frame frame= new Frame("test frame");
            		Checkbox cb= new Checkbox("test box");
            		
            		frame.add(cb);
            		frame.pack();
            		
            		cb.setEnabled(false);
            		frame.setVisible(true);
            	}
            }
            kind regards,

            Jos

            Comment

            • BSCode266
              New Member
              • Jan 2007
              • 38

              #7
              Code:
              cb.setBackground(prompt.style.backgroundColour);
              This probably is the reason it isn't greyed out. I never use AWT components, i love Swing better.

              Greets.

              ~BSCode266

              Comment

              Working...