JToolbar背景图片
我正在使用自定义的 JToolbar,代码如下:
public class GeneralToolbar extends JToolBar{
public GeneralToolbar() {
super();
setBackground(Color.white);
setOpaque(true);
setPreferredSize(new Dimension(54,54));
setMinimumSize(new Dimension(54,54));
setMaximumSize(new Dimension(54,54));
setSize(new Dimension(54,54));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Dimension size = this.getSize();
ImageIcon image = DefaultAction.createImageIcon("/com/aaa/resources/tabback");
g.drawImage(image.getImage(), 0,0, size.width, size.height, this);
}
}
现在可以看到图像了。但我的按钮周围有一个不透明的矩形。 我尝试将按钮不透明设置为 false,但它没有添加任何影响。 感谢您的支持
I'm using a customized JToolbar using the following code:
public class GeneralToolbar extends JToolBar{
public GeneralToolbar() {
super();
setBackground(Color.white);
setOpaque(true);
setPreferredSize(new Dimension(54,54));
setMinimumSize(new Dimension(54,54));
setMaximumSize(new Dimension(54,54));
setSize(new Dimension(54,54));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Dimension size = this.getSize();
ImageIcon image = DefaultAction.createImageIcon("/com/aaa/resources/tabback");
g.drawImage(image.getImage(), 0,0, size.width, size.height, this);
}
}
Now the image is seen. But I get a opaque rectangle around my buttons.
I tried to set the button opaque to false but it didn't add any affect.
Thank you for the support
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许你需要使用:
当然当你去掉Border之后,那么你就看不到点击按钮的效果了。
如果您需要更多帮助,请发布显示问题的 SSCCE。
Maybe you need to use:
Of course when you get rid of the Border, then you don't see the effect of clicking on the button.
If you need more help post your SSCCE showing the problem.