首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JToolbar背景图像

JToolbar背景图像
EN

Stack Overflow用户
提问于 2010-01-02 04:24:26
回答 2查看 2.1K关注 0票数 0

我使用的是一个自定义的JToolbar,使用的代码如下:

代码语言:javascript
复制
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,但没有添加任何效果。感谢您的支持

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-01-02 05:27:07

也许你需要使用:

代码语言:javascript
复制
button.setBorderPainted( false );
button.setContentAreaFilled( false );

当然,当你去掉边框的时候,你看不到点击按钮的效果。

如果您需要更多帮助,请发布您的SSCCE以显示问题。

票数 2
EN

Stack Overflow用户

发布于 2010-01-02 04:26:02

代码语言:javascript
复制
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);
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1989522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档