Reputation: 985
I have a program where i have a button to change the background color to red and another button to set back the default panel color.
How do i get back the default color for panel??
Upvotes: 0
Views: 8341
Reputation: 4960
Make sure you call JComponent.setOpaque(boolean)
for the component you're working with.... some Swing components default to opaque == false and just show the color of whatever is behind it (e.g. a button in a textured panel).
Upvotes: 1
Reputation: 1050
Store the default color to a variable in constructor or before changing the color with the other button, ie:
Color defaultColor = panel.getBackground();
And in your default color button:
panel.setBackground(defaultColor);
Upvotes: 1