一般用Eclipse开发的软件在windows上运行界面比较难看,如图所示:
解决办法是在 static main()函数中添加程序语句,改变当前界面风格,本文添加风格为Nimbus风格,代码如下:
<span style="font-size:18px;">public static void main(String[] args) {
//设置当前外观为Nimbus风格
<em><span style="color:#ff0000;">try{
for(LookAndFeelInfo info: UIManager.getInstalledLookAndFeels()){
if("Nimbus".equals(info.getName())){
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
}catch(Exception exception){
JOptionPane.showMessageDialog(null, "无法打开Nimbus界面");
}</span></em>
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
stFrame=new MainWindow();
stFrame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}</span>
新的界面如下: