Note that there are some explanatory texts on larger screens.

plurals
  1. POChange JButton's Disabled Foreground (Font) Color for Windows
    text
    copied!<p>I realize this sounds a LOT like many of the questions already posted out there, but please read on; this has a seemingly similar problem but has not worked with many solutions already provided.</p> <p>I am currently writing in Java with Eclipse on both OS X and Windows. With OS X, I have a JButton that goes from .setEnabled(true) to .setEnabled(false). When this happens, as it gets disabled, I change its background color via .setBackground(someColor). The entire time this is happening, the foreground (font) color does not change and stays black. This is what I want, it's perfect the way it is.</p> <p>Then comes the problem with Windows. Same as above, I have a JButton that goes from .setEnabled(true) to .setEnabled(false). I also change its background via .setBackground(someColor). However, when this happens, the foreground (font) color does not stay constant – it changes from black to a light gray. This is extremely inconvenient and makes it very hard to read with the new background color.</p> <p>So the question is: How do I change the foreground color of a disabled JButton?</p> <p>I have already tried the following:</p> <pre><code>button.setForeground(Color.BLACK); button.setText(&lt;html&gt;&lt;font color = black&gt;BUTTON&lt;/font&gt;&lt;/html&gt;); UIManager.put("Button.disabledText", Color.BLACK); UIManager.getDefaults().put("Button.disabledText", Color.BLACK); UIManager.put("Button.foreground", Color.BLACK); UIManager.getDefaults().put("Button.foreground", Color.BLACK); </code></pre> <p>None of it worked. And I've also tried the following:</p> <ul> <li>Exporting the OS X to a .jar file, then using it in Windows. Windows font color still changes.</li> <li>Compiling an .app file for OS X and an .exe file for Windows. The problem still remains.</li> </ul> <p>Is there ANY other solution out there that I've overlooked?</p> <p>At the moment, I've resorted to leaving the font as the unsightly gray it currently is and changing the background (which, for some reason, can still easily be changed via .setBackground()) to other colors that can accommodate it.</p> <p>So why does there seem to be this color difference between OS X and Windows? I prefer the OS X color scheme, but I don't really want to have 2 sets of code for what is essentially the same program.</p> <p>What should I do?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload