透明JButton
是否可以使 JButton 透明(包括边框)但不透明文本?我扩展了 swing 的 JButton 并覆盖了它:
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0));
super.paint(g2);
g2.dispose();
}
但它使所有内容都透明,包括文本。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下应该可以解决问题。
The following should do the trick.
您的程序的用户不能将您的按钮视为按钮。使用时可以认为它是一个Label。所以我的解决方案是半透明的,出现 &消失的边界。
此代码改进,改进的代码,更好,性能更好,更美观,更适合。
我的输出
The user of you program can not citified your Button as a button. Use can think it is a Label. So my Solution is half transparent with appearing & disappearing border.
This code is improved, improved codes, better, better performance, more beautiful, pro-fit.
My output