"but the problem is that I have a JButton on the animated JPanel. "
Don't put the button on the same panel then. Learn to use layout managers. With your image, I would use nested JPanel
s with BorderLayout
s
The right side
JButton button = new JButton();
JPanel animatedPanel = new JPanel();
Add them to another JPanel
JPanel rightPanel = new JPanel(new BorderLayout());
rightPanel.add(button, BorderLayout.NORTH);
rightPanel.add(animatedPanel, BorderLayout.CENTER);
/** result **/
+-----+
| |
| |
+-----+
| |
| |
| |
| |
| |
+-----+
Then create another JPanel to hold the BigPanel and the RightPanel
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel leftBigPanel = new JPanel();
mainPanel.add(leftBigPanel, BorderLayout.CENTER);
mainPanel.add(rightPanel);
/** result **/
*--------------------+-----+
| | |
| | |
| +-----+
| | |
| | |
| | |
| | |
| | |
+--------------------+-----+
The button no longer overlaps the right animated panel
- Note : @override the
getPreferredSize()
in the JPanels for your desired dimension.