Java - 如何用颜色填充Windows L& F按钮,而不只是边框? [英] Java - How to fill a Windows L&F button with color instead of just the border?

查看:361
本文介绍了Java - 如何用颜色填充Windows L& F按钮,而不只是边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7上使用Java做了一些GUI测试。我想使用Windows Look&感觉因为Java的默认金属UI是真的丑陋IMO。当我设置按钮的背景颜色时,它只是在按钮周围的边框颜色,而不是填充其整个背景。

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);
    }
}

结果是:

然而我的目标是这样的(但不使用Metal L& F):

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

有办法做到这一点与Windows L& ; F或者它根本不是内置的?

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

推荐答案

一些PLAF支持

一种实现你想要的方式是在带有绿色BG的图像中写入按钮文本,并使用图像来显示按钮无文本。

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.

这篇关于Java - 如何用颜色填充Windows L& F按钮,而不只是边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆