spozzi
spozzi

Reputation: 77

Make JButton paintComponent draw on top of parent's border

I have a verticalBox with a border of 1px on all sides. Insede the vb there are buttons. I would like for the selected button to draw on top of the right border of the vb. The desired result would be a continous line except for where the selected button is.

I unsuccessfully tried overriding the paintComponent of the button as follows:

@Override
 protected void paintComponent(final Graphics g) {
    Graphics2D g2 = (Graphics2D)g.create();
    g2.setColor(Color.WHITE);
    shape = new Rectangle(0,0, this.getWidth() + 1, this.getHeight());
    g2.fill(shape);
    super.paintComponent(g);
    g2.dispose();
}

this is my verticalBox instantiaton:

Box typeVerticalBox = Box.createVerticalBox();
typeVerticalBox.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new Color(220,220,220)));

Upvotes: 0

Views: 18

Answers (0)

Related Questions