如何使JButton仅显示背景颜色?我不需要其他效果,例如边框、3D外观或悬停高亮显示。
提前感谢。
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);
?
首先,将您的外观设置为酷炫的样式,比如“金属”。
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);
我认为你可以这样做
JButton button = new JButton("Click Me!!");
button.setBorderPainted(false);
button.setBackground(new Color());// inside the brackets your rgb color value like 255,255,255
button.setFocusPainted(false);
你可以使用颜色选择器获取RGB代码(只需搜索颜色选择器)
ButtonUI
来控制它。 - McDowell