重写 JButton 中的 Paint() 方法
我有一个扩展 JButton 的类,因为我使用的自定义外观和感觉会忽略 isOpaque() 调用。我的意思是,即使我在按钮和所有父面板上调用了 setOpaque (false),按钮的背景也会呈现。我已经从公司设计人员处确认这是 LAF 的问题,所以除了扩展课程之外我无能为力。 所以我的问题是,如何实现 Paint() 方法以不渲染背景而仅渲染按钮图标? 干杯
已解决:万一有人感兴趣,我想要的答案是使用 button.setContentAreaFilled(false);
I have a class that extends JButton because the custom look and feel I'm using ignores the isOpaque() call. What I mean is, the background of the button is rendered even though I have called setOpaque (false) on it and all parent panels. I have confirmed that this is an issue with the LAF from the companies design people so there is nothing I can do but extend the class.
So my question is, how can I implement the paint() method to not render the background and just the button icon?
Cheers
SOLVED: The answer I was after in case anyone is interested was to use button.setContentAreaFilled(false);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
绘画是通过三个方法完成的:paintComponent、paintBorder 和paintChildren。它们按该顺序调用,并且第一个绘制组件的背景。如果您超载了其中一个并保留了其他两个,那么应该没问题。
Painting is done by three methods: paintComponent, paintBorder, and paintChildren. They're called in that order and it's the first that paints the component's background. If you overload that one and leave the other two, you should be fine.