java 按钮边框无色,Java - 如何用颜色填充Windows L& F按钮,而不只是边框?

I'm doing a few GUI tests with Java on Windows 7. I would like to use the Windows Look & Feel because Java's default "Metal" UI is really ugly IMO. When I set the background color of a button, it just colors the border around the button rather than fill its whole background.

public class GUITest {

public static void main(String[] args) {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch(Exception e) {} // I know, not a good idea, but it's just a test

JFrame frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setLayout(new FlowLayout());

JButton button = new JButton("Windows L&F");

button.setFocusable(false);

button.setBackground(Color.GREEN.darker());

frame.add(button);

frame.pack();

frame.setLocationRelativeTo(null);

frame.setVisible(true);

}

}

The result is this:

jwmdV.png

Whereas I'm aiming for something like this (but without using the Metal L&F):

Ptpet.png

Is there a way to do that with the Windows L&F, or is it simply not built in?

解决方案

Some PLAFs support (custom) colored buttons. Others don't.

One way to achieve what you seem to want is to write the button text in an image with green BG and use the image for an icon of a button without text.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值