473,372 Members | 859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 10702
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

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

Similar topics

0
by: Melanie | last post by:
Hallo Ich habe folgendes Problem: In einem JPanel zeige ich mehrere Textfelder und RadioButtons an. Mit den RadioButtons sorge ich dafür, dass das Textfeld welches ausgewählt wurde nicht...
11
by: JPRoot | last post by:
Hi I wish to set/get a property using System.ComponentModel.ISynchronizeInvoke.Invoke but I cannot find the exact syntax.. Any clue how to do this (right now I am making GetEnabled/SetEnabled...
6
by: tshad | last post by:
I am trying to disable and enable a checkbox from javascript. The problem is that if the checkbox starts out as: <input id="Override" type="checkbox" name="Override"/> I can change it back...
2
by: waterox | last post by:
Hi, I am trying to hack this mp3 player so that it displays 3 levels of hierarchy instead of 2. Check out the current player here http://www.yanwhite.com/staging/GetGoodMusic/music.htm ...
6
blazedaces
by: blazedaces | last post by:
Hey, so here's an example of what I want to do: This "window" if you will, or simple gui, will accept an ArrayList<String> and in turn spit out for every one of them a checkbox and a text field...
3
by: bartek20 | last post by:
Hey, Im trying to get my gui working but am having a few issues. I have 3 classes, main, mainWindow, and errorWindow. the mainWindow is instantiated from main as mainWindow m1 = new...
2
by: vijayrvs | last post by:
SearchCrawler.java The program search crawler used to search the files from the website. From the following program i got 7 compiler error. can any body clarify it and provide me solution. ...
0
by: ambassador | last post by:
good day guys, please help: i'm having trouble of displaying my data from ms access database to JList. if there's someone could help me, i would greatly appreciate it. i'm using netbeans 6.0...
0
by: Michael Pearson | last post by:
I currently have two know problems with my current code. First, I can't seem to get the image to display. I have the gallows already displaying and I want to get the head (that is the next pic that...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.