UIManager, how to get values of different LookAndFeels?

KaNaDa :

I need to get the default background color of a TableHeader but of the Windows LookAndFeel. I have already tried:

try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    System.out.println(UIManager.getColor("TableHeader.background"));
catch (Exception e) {
    e.printStackTrace();
}

But it just returns the default color (so the Metal theme one). How do I get the background color of a component from a specific LookAndFeel?

PS.

In this case

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

is the same as

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

EDIT:

Ok I found out, why it returns a "wrong" value for TabHeaader.background. That's because the color I want is not the TabHeader.background or TabHeader.foreground. But do one know how one get the color of the "background"?

EDIT 2:

I found out, that header.setBackground(COLOR); works if you are on default theme. But when I set LookAndFeel on Windows look and feel header.setBackground(COLOR) changes the border color.

Marco R. :

The Windows look and feel is defined in the LookAndFeel class com.sun.java.swing.plaf.windows.WindowsLookAndFeel. You can use it by invoking the UIManager.setLookAndFeel with fully qualified class name as an argument:

    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        System.out.println(UIManager.getColor("TableHeader.background"));
    } catch (Exception ex) {
        // HANDLE EXCEPTION
    }

This is the list of the available look and feels in the Swing framework: https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html#available

Hope this helps.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=100418&siteId=1