?
Solved

I want JCheckBox Disabled color to be black. Any workaround ?

Posted on 2001-07-17
17
Medium Priority
?
1,081 Views
Last Modified: 2008-01-09
Hi,
   I have JCheckBox and other components in a panel and I will print the panel. Before printing I will disable the JCheckBox and will show the user. After disabling, the JCheckBox Forground color is Gray and if i print it, it is hardly visible. Is it possible to change the fore ground color of the JCheckBox to Black for printing ??

   Any suggestion or workaround is welcome.

Regards,
Prem.
0
Comment
Question by:PremkumarAC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
  • +2
17 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 6289127
YourCheckBox.setForeground(yourColor);
Will work even if is disabled.
0
 
LVL 92

Expert Comment

by:objects
ID: 6289129
Why are you disabling it?
0
 

Author Comment

by:PremkumarAC
ID: 6289152
Hi Ovi,
   My code is like this:

boolean flag = ...; // i will read the data from a model
myCheckBox.setForeground( Color.black);
myCheckBox.setEnabled( flag);

But, still the check box is disabled and the color is gray and i am getting the same color in the hard copy.

Hi Objects,
   I am reading the values from the model, so i am disabling the JCheckBox.

Regards,
Prem.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 9

Expert Comment

by:Ovi
ID: 6289162
f you set the color other to the black before you disable'it you will see the difference.
The checkbox renderer only make a graphic filter on the foreground so a black foreground will become a less black one (gray) after the check box i disabled.
0
 
LVL 92

Expert Comment

by:objects
ID: 6289166
Still don't exactly inderstand your reason for disabling but why not use a glass pane instead of disabling the checkbox?

0
 
LVL 9

Expert Comment

by:Ovi
ID: 6289169
boolean flag = ...; // i will read the data from a model
//  myCheckBox.setForeground( Color.black);
myCheckBox.setEnabled( flag);
myCheckBox.setForeground(Color.blue); // or new Color(int, int, int);
0
 
LVL 92

Expert Comment

by:objects
ID: 6289185
If you want control of the disabled icon the you can explicitly set it using setDisabledIcon() setDisabledSelectedIcon() method:

eg.

cb.setDisabledIcon(cb.getIcon());
cb.setDisabledSelectedIcon(cb.getSelectedIcon());

will use the same icon when disabled as it does when it is enabled.
0
 

Author Comment

by:PremkumarAC
ID: 6289206
Is it possible to add a glassPane to a JPanel ??
0
 
LVL 92

Expert Comment

by:objects
ID: 6289232
No but your frame will have one.
0
 

Author Comment

by:PremkumarAC
ID: 6289269
Is it possible to add a glassPane to a JPanel ??
0
 
LVL 92

Expert Comment

by:objects
ID: 6289280
No, you just use the one on your frame.
0
 

Author Comment

by:PremkumarAC
ID: 6289358
My parent component is Frame and not JFrame. So I think it is not possible to use Glass pane over my component.
0
 
LVL 92

Expert Comment

by:objects
ID: 6289380
You could possibly switch to a JFrame.
Or define the disable icon you want to use as I suggested above.
Or find an alternative to disabling.

Your decision really :)

0
 

Author Comment

by:PremkumarAC
ID: 6298120
checkBox.setForeGround( color) won't work when the checkbox is disabled.
0
 
LVL 92

Expert Comment

by:objects
ID: 6300487
Then simply assign the disabled icon that you want to use explicitly as I described above.
I believe it only greys out the icon, if you have not explicitly defined one.
0
 
LVL 5

Expert Comment

by:vemul
ID: 7669726
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points NOT refunded
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7714687
Per recommendation, points NOT refunded and question closed.

Netminder
EE Admin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question