如何制作简单平面风格的JButton?

什么是最简单的方法,使JButton只显示背景颜色? 我不需要任何其他效果,如边框,3D外观或hover突出显示。

提前致谢。

我不知道我是否错过了一点……但我通常会这样做:

 button.setBorderPainted(false); button.setFocusPainted(false); button.setContentAreaFilled(false); 

只需设置颜色和边框:

 private static JButton createSimpleButton(String text) { JButton button = new JButton(text); button.setForeground(Color.BLACK); button.setBackground(Color.WHITE); Border line = new LineBorder(Color.BLACK); Border margin = new EmptyBorder(5, 15, 5, 15); Border compound = new CompoundBorder(line, margin); button.setBorder(compound); return button; } 

使用setOpaque(false); 使背景透明。

怎么样

 yourButton.setBorder(null); 

您可能希望使用带有MouseListener的JLabel …除非您以某种方式使用JButton或ActionListener。

首先,将你的外观和感觉设置为酷炫的东西,比如’金属’。

 try { for (UIManager.LookAndFeelInfo lnf : UIManager.getInstalledLookAndFeels()) { if ("Metal".equals(lnf.getName())) { UIManager.setLookAndFeel(lnf.getClassName()); break; } } } catch (Exception e) { /* Lazy handling this >.> */ } 

然后做这样的事情:

 my_jbutton.setBackground(new Color(240,240,241); 

如果按钮的颜色与旋转控件颜色(240,240,240)完全相同,则窗口将按钮样式应用类似窗口的按钮样式,否则按钮采用简单的平面样式。