透明 JButton [英] Transparent JButton

查看:20
本文介绍了透明 JButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使 JButton 透明(包括边框)而不是文本?我扩展了 Swing 的 JButton 并覆盖了它:

Is it possible to make a JButton transparent (including the border) but not the text? I extend swing's JButton and override this:

@Override
public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0));
    super.paint(g2);
    g2.dispose();
}

但它使一切都透明,包括文本.谢谢.

but it makes everything transparent, including the text. Thanks.

推荐答案

button.setOpaque(false);
button.setContentAreaFilled(false);
button.setBorderPainted(false);

这篇关于透明 JButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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