By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

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

P: 3
---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
Share this Question
Share on Google+
6 Replies


Expert 10K+
P: 11,448
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

P: 3
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

Expert 10K+
P: 11,448
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

P: 3
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

Expert 10K+
P: 11,448
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

BSCode266
P: 38
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.