bcd
bcd

Reputation: 13

Swing: how to paint an animation over every component, JPanel, JButton, etc?

I'm trying to paint over every component in my Swing application.

what I have:

jButton b = new JButton();
b.addActionListener(e -> fillEntireScreen())
f.add(b);
f.setVisible()...f.setSize()...f.setDefaultCloseOperation()...

where fillEntireScreen() simply is an animation that expands over the screen. I override Component's paintComponent(), painting over the frame, not a panel or anything. fileEntireScreen() works without the button, but does not work when I add the button, as the animation is behind the button.

how can I paint over the button? Thanks!

Upvotes: 1

Views: 73

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347314

Use a glassPane instead - See How to Use Root Panes for more details and How can I paint in an specific JPanel when more than one in same frame- Java for an example.

Alternatively you could use a JLayer, but's more complicated and may not suit your needs. See How to Decorate Components with the JLayer Class

Upvotes: 1

Related Questions