[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1199
  • Last Modified:

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

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
PremkumarAC
Asked:
PremkumarAC
  • 7
  • 5
  • 3
  • +2
1 Solution
 
OviCommented:
YourCheckBox.setForeground(yourColor);
Will work even if is disabled.
0
 
objectsCommented:
Why are you disabling it?
0
 
PremkumarACAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
OviCommented:
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
 
objectsCommented:
Still don't exactly inderstand your reason for disabling but why not use a glass pane instead of disabling the checkbox?

0
 
OviCommented:
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
 
objectsCommented:
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
 
PremkumarACAuthor Commented:
Is it possible to add a glassPane to a JPanel ??
0
 
objectsCommented:
No but your frame will have one.
0
 
PremkumarACAuthor Commented:
Is it possible to add a glassPane to a JPanel ??
0
 
objectsCommented:
No, you just use the one on your frame.
0
 
PremkumarACAuthor Commented:
My parent component is Frame and not JFrame. So I think it is not possible to use Glass pane over my component.
0
 
objectsCommented:
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
 
PremkumarACAuthor Commented:
checkBox.setForeGround( color) won't work when the checkbox is disabled.
0
 
objectsCommented:
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
 
vemulCommented:
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
 
NetminderCommented:
Per recommendation, points NOT refunded and question closed.

Netminder
EE Admin
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 7
  • 5
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now