基于线程如何使用 Nimbus 外观和感觉更改 JPanel 的背景颜色?可以从 中更改和分配一个值Nimbus Defaults
,
但是你确定你需要这个输出到 GUI,没什么好说的
与 Nimbus L&F 的基本 JButton 对比
从代码
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.InsetsUIResource;
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.setSize(200, 100);
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("Button.contentMargins", new InsetsUIResource(0,0,0,0));
}
}
} catch (Exception e) {
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
NimbusJPanelBackGround nimbusJPanelBackGround = new NimbusJPanelBackGround();
}
});
}
}
以前为有趣的问题 +1