Search code examples
javaswingjbutton

Transparent JButton


Is it possible to make a JButton transparent (including the border) but not the text? I extend swing's JButton and override this:

@Override
public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0));
    super.paint(g2);
    g2.dispose();
}

but it makes everything transparent, including the text. Thanks.


Solution

  • button.setOpaque(false);
    button.setContentAreaFilled(false);
    button.setBorderPainted(false);