Nimbus Default为 Nimbus 外观和感觉提供简单的矩阵,但需要覆盖所有相关的鼠标和焦点事件,而不覆盖......可能只是,
从代码
import com.sun.java.swing.Painter;
import java.awt.*;
import javax.swing.*;
public class NimbusJPanelBackGround {
public NimbusJPanelBackGround() {
JButton btn = new JButton(" Whatever ");
JButton btn1 = new JButton(" Whatever ");
JPanel p = new JPanel();
p.add(btn);
p.add(btn1);
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.add(p, BorderLayout.CENTER);
f.pack();
f.setLocation(150, 150);
f.setVisible(true);
}
public static void main(String[] args) {
try {
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(laf.getName())) {
UIManager.setLookAndFeel(laf.getClassName());
UIManager.getLookAndFeelDefaults().put("Panel.background", Color.white);
UIManager.getLookAndFeelDefaults().put("nimbusFocus", Color.blue);
UIManager.getLookAndFeelDefaults().put("Button[Focused+MouseOver].backgroundPainter",
new FillPainter(new Color(127, 255, 191)));
UIManager.getLookAndFeelDefaults().put("Button[MouseOver].backgroundPainter",
new FillPainter(new Color(127, 255, 191)));
}
}
} catch (Exception e) {
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
NimbusJPanelBackGround nimbusJPanelBackGround = new NimbusJPanelBackGround();
}
});
}
}
class FillPainter implements Painter<JComponent> {
private final Color color;
public FillPainter1(Color c) {
color = c;
}
@Override
public void paint(Graphics2D g, JComponent object, int width, int height) {
g.setColor(color);
g.fillRect(0, 0, width - 1, height - 1);
}
}