Sonoman
Sonoman

Reputation: 3429

Overriding the paint() method in JButton

I have a class that extends JButton because the custom look and feel I'm using ignores the isOpaque() call. What I mean is, the background of the button is rendered even though I have called setOpaque (false) on it and all parent panels. I have confirmed that this is an issue with the LAF from the companies design people so there is nothing I can do but extend the class. So my question is, how can I implement the paint() method to not render the background and just the button icon? Cheers

SOLVED: The answer I was after in case anyone is interested was to use button.setContentAreaFilled(false);

Upvotes: 0

Views: 2850

Answers (1)

Kaffiene
Kaffiene

Reputation: 713

Painting is done by three methods: paintComponent, paintBorder, and paintChildren. They're called in that order and it's the first that paints the component's background. If you overload that one and leave the other two, you should be fine.

Upvotes: 5

Related Questions