public static void changeLaf(JComponent component, String laf) {
try {
UIManager.setLookAndFeel(laf);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
}
SwingUtilities.updateComponentTreeUI(component);
}
如何使用它?
changeLaf(/*your JPopupMenu*/, /*your ClassName laf*/);
这里
JPopupMenu pmLAF = new JPopupMenu();
JMenuItem miRandomColor = new JMenuItem("Set Random Color");
JMenuItem miWhiteColor = new JMenuItem("Set White Color");
JMenuItem miDefaultColor = new JMenuItem("Set Default Color");
pmLAF.add(miRandomColor);
pmLAF.add(miWhiteColor);
pmLAF.addSeparator();
pmLAF.add(miDefaultColor);
JLabel lblMetal = new JLabel(" Metal ");
lblMetal.setBorder(BorderFactory.createEtchedBorder());
JLabel lblMotif = new JLabel(" Motif ");
lblMotif.setBorder(BorderFactory.createEtchedBorder());
JLabel lblNimbus = new JLabel(" Nimbus ");
lblNimbus.setBorder(BorderFactory.createEtchedBorder());
我将 LAF 固定为 Labels 并更改为 JPopupMenu
changeLaf(pmLAF, /*Change LAF String*/);
changeLaf(lblMetal, "javax.swing.plaf.metal.MetalLookAndFeel");
changeLaf(lblMotif, "com.sun.java.swing.plaf.motif.MotifLookAndFeel");
changeLaf(lblNimbus, "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
视窗 LAF
雨云LAF
母题 LAF
金属 LAF
一些类名
/*
# --laf javax.swing.plaf.mac.MacLookAndFeel
# --laf apple.laf.AquaLookAndFeel
# --laf com.apple.laf.AquaLookAndFeel
# --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel
# --laf com.sun.java.swing.plaf.motif.MotifLookAndFeel
# --laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
# --laf com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel
# --laf com.sun.java.swing.plaf.windows.WindowsLookAndFeel
# --laf javax.swing.plaf.basic.BasicLookAndFeel
# --laf javax.swing.plaf.metal.MetalLookAndFeel
# --laf javax.swing.plaf.multi.MultiLookAndFeel
# --laf javax.swing.plaf.synth.SynthLookAndFeel
# --laf javax.swing.plaf.nimbus.NimbusLookAndFeel
# --laf it.unitn.ing.swing.plaf.macos.MacOSLookAndFeel
*/