当我在工具栏中使用 JToolbar 和 JButton 时,我遇到了 Nimbus 外观问题。如果我使用 Metal,我只有 Nimbus 的问题,按钮显示正确。
ToolBar 中的按钮仅在单击或鼠标悬停时才可见,而在 Metal 中它们是标准可见的。我的问题或疑问,是否有解决此问题的方法?
示例代码:
按钮:测试,test1 在工具栏中,不可见,按钮 test2 不在工具栏中,看起来很正常,我希望按钮测试,test1 看起来像 test2,只是它们在工具栏中。
import java.awt.FlowLayout;
import javax.swing.*;
public class nimbus extends JFrame{
public nimbus()
{
//setLook("javax.swing.plaf.metal.MetalLookAndFeel");
setLook("javax.swing.plaf.nimbus.NimbusLookAndFeel");
FlowLayout fl = new FlowLayout();
fl.setAlignment(fl.LEFT);
this.setLayout(fl);
this.setSize(100, 200);
JToolBar tbar = new JToolBar();
tbar.setLayout(fl);
tbar.setSize(800, 40);
tbar.setFloatable(false);
JButton btn = new JButton("test");
btn.setSize(50, 23);
tbar.add(btn);
btn = new JButton("test1");
btn.setSize(50, 23);
tbar.add(btn);
this.add(tbar);
btn = new JButton("test2");
btn.setSize(50, 23);
this.add(btn);
}
public static void main(String[] args){
nimbus n = new nimbus();
n.setVisible(true);
}
public void setLook(String look)
{
try {
UIManager.setLookAndFeel(look);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}