JToolbar background image
I am using a custom 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);
}
}
The image is now visible. But I am getting an opaque rectangle around my buttons. I tried setting the opaque button to false, but it didn't add any effect. thanks for the support
0
Guy
source
to share
2 answers
Perhaps you need to use:
button.setBorderPainted( false );
button.setContentAreaFilled( false );
Of course, when you get rid of the border, you don't see the button click effect.
If you need more help please post a SSCCE showing the problem.
+2
camickr
source
to share
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
Guy
source
to share