471,851 Members | 979 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,851 software developers and data experts.

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

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

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(false) but still it is not grayed out. Anybody knows how to gray out checkbox in jdk 1.6?
Jan 20 '09 #1
6 10555
JosAH
11,448 Expert 8TB
That's strange; I use Java 1.6 (update 11) but those check boxes are greyed when disabled (indeed, use the setEnabled(false) 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
Jan 20 '09 #2
public void populateRadioButtons() {
Enumeration e = widgets.elements();
while (e.hasMoreElements()) {
prompt.removeWidget((Component) e.nextElement());
}
widgets = new Vector();
CheckboxGroup cbg = new CheckboxGroup();
String[] choice;
extractChoices();
e = choices.elements();
Checkbox cb;
while (e.hasMoreElements()) {
choice = (String[]) (e.nextElement());
cb = new Checkbox();
cb.setBackground(prompt.style.backgroundColour);
cb.setCheckboxGroup(cbg);
prompt.addWidget(cb);
if (readOnly) {
//cb.disable();
cb.setEnabled(false);
}
widgets.addElement(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()).setState(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()).select(i);
else
((Checkbox) widgets.elementAt(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()).select(i);
else
((Checkbox) widgets.elementAt(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 populateRadioButtons() 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?
Jan 21 '09 #3
JosAH
11,448 Expert 8TB
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
Jan 21 '09 #4
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?
Jan 22 '09 #5
JosAH
11,448 Expert 8TB
I don't know what's happening on your computer but the following test snippet runs fine on my machine:

Expand|Select|Wrap|Line Numbers
  1. import java.awt.Checkbox;
  2. import java.awt.Frame;
  3.  
  4. class Test {
  5.  
  6.     public static void main (String[] args) {
  7.  
  8.         Frame frame= new Frame("test frame");
  9.         Checkbox cb= new Checkbox("test box");
  10.  
  11.         frame.add(cb);
  12.         frame.pack();
  13.  
  14.         cb.setEnabled(false);
  15.         frame.setVisible(true);
  16.     }
  17. }
  18.  
kind regards,

Jos
Jan 22 '09 #6
Expand|Select|Wrap|Line Numbers
  1. 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
Jan 23 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Melanie | last post: by
11 posts views Thread by JPRoot | last post: by
6 posts views Thread by tshad | last post: by
blazedaces
6 posts views Thread by blazedaces | last post: by
3 posts views Thread by bartek20 | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.