如何更改 JComboBox 中的箭头样式

发布于 2024-09-05 04:06:31 字数 158 浏览 3 评论 0 原文

假设我想在 JComboBox 中使用自定义图像作为箭头,我该怎么做?

我知道可以使用合成 xml 文件,甚至可能使用 UIManager.put(...),但我不知道如何。此时我想做的就是将箭头图像更改为其他图像,或者以编程方式,或者甚至只是覆盖它使用的图像。我究竟该如何做到这一点?

Let's say I want to use a custom image for the arrow in JComboBox, how can I do this?

I understand it's possible using the synth xml files, or maybe even UIManager.put(...), but I don't know how. All I want to do at this time is change the arrow image to something else, either programatically or even just overriding the image it uses. How exactly can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撑一把青伞 2024-09-12 04:06:47

您可以在 createArrowButton() ="noreferrer">BasicComboBoxUIBasicArrowButton< /a> 是一个方便的起点。

class ColorArrowUI extends BasicComboBoxUI {

    public static ComboBoxUI createUI(JComponent c) {
        return new ColorArrowUI();
    }

    @Override protected JButton createArrowButton() {
        return new BasicArrowButton(
            BasicArrowButton.SOUTH,
            Color.cyan, Color.magenta,
            Color.yellow, Color.blue);
    }
}

然后安装它。

JComboBox combo = new JComboBox();
combo.setUI(ColorArrowUI.createUI(combo));

You can override createArrowButton() in BasicComboBoxUI. BasicArrowButton is a convenient starting point.

class ColorArrowUI extends BasicComboBoxUI {

    public static ComboBoxUI createUI(JComponent c) {
        return new ColorArrowUI();
    }

    @Override protected JButton createArrowButton() {
        return new BasicArrowButton(
            BasicArrowButton.SOUTH,
            Color.cyan, Color.magenta,
            Color.yellow, Color.blue);
    }
}

Then install it.

JComboBox combo = new JComboBox();
combo.setUI(ColorArrowUI.createUI(combo));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文