axelrod
axelrod

Reputation: 3978

Change disabled color of Swing link label

I'm using Java Swing linkLabel. When the link is disabled the default color is gray but I want it to be black. Is there a way to change the color of disabled link label?

Upvotes: 1

Views: 1016

Answers (4)

trashgod
trashgod

Reputation: 205785

It's not supported by all Look & Feel implementations, but you could try changing the UI default before instantiating any GUI elements:

UIManager.put("Label.disabledForeground", Color.black);

Upvotes: 3

user529543
user529543

Reputation:

yes, it is un the UIDefaults just print out all keys, pick that one what need to be modified and change the value. AFTER that launch the GUI

That will change all Label color in your application, not only 1 instance.

Upvotes: 2

NoNaMe
NoNaMe

Reputation: 6222

You may try this using HTML tags e-g

welcomeLabel.setText(this.htmlIfy("<p style='color:#000000;'>Welcome</p>"));

where the htmlIfy function is

private static final String HTML = "<html>";
    private static final String HTML_END = "</html>";
public static String htmlIfy(String s) {
        return HTML.concat(s).concat(HTML_END);
    }

Upvotes: 1

mKorbel
mKorbel

Reputation: 109813

for JLabel you have to change opacity, because JLabel is transparent by default

JLabel.setOpaque(true);
JLabel.repaint(); 
// not required in most cases, but missed for MouseEvents in the API

Upvotes: 3

Related Questions