I have an application which is using windows look and feel. As soon as I change the theme of windows to high contrast theme, all my application color gets changes even when I have set the default colors . Can anyone tell me a work around.
-
Can you include your code for us to see where it goes wrong – Lokesh Pandey Oct 12 '17 at 11:19
1 Answers
AVA UI - Applying windows look and feel with High contrast theme
It is the responsibility of each L&F to provide a concrete implementation for each of the ComponentUI subclasses defined by Swing. For example, the Java Look and Feel creates an instance of MetalTabbedPaneUI to provide the L&F for JTabbedPane. The actual creation of the UI delegate is handled by Swing for you—for the most part you never need to interact directly with the UI delegate.
Just try switching on these two options before frames/dialogs creation:
AnyJavaContainers.setDefaultLookAndFeelDecorated ( true );
//For exapmle:
JDialog.setDefaultLookAndFeelDecorated ( true );
JFrame.setDefaultLookAndFeelDecorated ( true );
Component created before the LAF change can know about it
SwingUtilities.updateComponentTreeUI(someComponent);
JFileChooser window L&F: similar example No 1 & similar example No 2.
For more How to Set the Look and Feel and How It's works -By Oracle Documentation
Using Darryl's Swing Utils more customize controle over Java Swing Application
Download Darryl's Swing Utils , read descriptions, then run (Darryl's) code, result is selection for JFileChooser (I voting for this question, If you understand from my answer and approve as correct answer)
For exapmle
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
import javax.swing.plaf.metal.MetalButtonUI;
public class CrazyFileChooser {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new CrazyFileChooser().makeUI();
}
});
}
public void makeUI() {
JFileChooser chooser = new JFileChooser();
for (AbstractButton button : SwingUtils.getDescendantsOfType(AbstractButton.class, chooser)) {
button.setUI(new XORButtonUI());
}
for (JList list : SwingUtils.getDescendantsOfType(JList.class, chooser)) {
list.setBackground(Color.PINK);
}
chooser.showOpenDialog(null);
}
}
class XORButtonUI extends MetalButtonUI {
@Override
public void paint(Graphics g, JComponent c) {
g.setXORMode(Color.YELLOW);
super.paint(g, c);
}
}
-
I agree with you but my my pint of worry is this : Suppose we have a file chooser, I ahev applied all the colors in UIManager, but when the file chooser opens , it is showing black background for the file content, that is because it picking windows color, so is there any way to only pick look and feel without picking colors – SQL developer Oct 13 '17 at 03:36
-
@RishabhKhandelwal I update my answer with some similar example and 3rd party library, If you still unable to find your issue update your question with your code other then I devote your question, However I recommended to review Java **UIManager** class https://docs.oracle.com/javase/7/docs/api/javax/swing/UIManager.html and oracle L&F docs https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/lookandfeel/LookAndFeelDemoProject/src/lookandfeel/LookAndFeelDemo.java – Oct 13 '17 at 08:05