绘制一个看起来像JLabel的JButton(或者至少没有按钮边缘?) [英] Draw a JButton to look like a JLabel (or at least without the button edge?)

查看:83
本文介绍了绘制一个看起来像JLabel的JButton(或者至少没有按钮边缘?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JButton,由于各种原因我想像按钮一样,但看起来像JLabel。它实际上并不一定是引擎盖下的JLabel,我只是不希望凸起的按钮边缘显示出来。

I've got a JButton that for various reasons I want to act like a button, but look like a JLabel. It doesn't actually have to be a JLabel under the hood, I just don't want the raised button edge to show up.

是否有一种简单的方法可以转动关闭JButtons的按钮外观,但保留所有按钮功能?

Is there an easy way to turn off the "button look" for JButtons but keep all the button functionality?

我可以构建某种组合的子类超级按钮,委托给jlabel进行显示,但是我我真的希望有一些东西沿着 button.lookLikeAButton(false)

I could build some kind of composed subclass hyperbutton that delegated to a jlabel for display purposes, but I'm really hoping there's something along the lines of button.lookLikeAButton(false).

推荐答案

您需要执行以下操作:

        setFocusPainted(false);
        setMargin(new Insets(0, 0, 0, 0));
        setContentAreaFilled(false);
        setBorderPainted(false);
        setOpaque(false);

您可能想要排除 setFocusPainted(false)如果你想让它实际绘制焦点(例如Windows外观上的虚线边框)。

You may want to exclude setFocusPainted(false) if you want it to actually paint the focus (e.g. dotted line border on Windows look and feel).

我已经使用了上面的代码仅限图标按钮。

I have used the above code in cases where I have wanted an "icon only" button.

这篇关于绘制一个看起来像JLabel的JButton(或者至少没有按钮边缘?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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