APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Background Color post and replies

Return to the Background Color thread
Login to post to this thread

Color for buttons
Apostolos Michaloudis
28 Posts

I have notice that when not given a backgroung color to a button, it has a nice silver like color which it seems very nice.

I want to make a button change color on click, like :
buttonColor = new java.awt.Color(red, green, blue);
and then, i want to change it's color back to this nice default color.
What are the parameters for this color?

Also, it would be nice if we could put background images to buttons.
Is this possible?
I don't mean in drawing panel but for buttons or two state buttons.


Replies to Color for buttons

Re: Color for buttons -
Francisco Esquembre
228 Posts

Hi,

To get the original color, use the following sentence:
originalColorButton = _view.button.getBackground();

and then set the color directly to the button using:
_view.setBackground (originalColorButton);

See example attached.

And although setting an image for the background of the button would imply modifying borders and other things, it is very easy to use a Label for this. Run the example attached and click on the green folder icon. This is a Label with an image and an action.

Paco

Attached File: ejs_src_ColorTest.zip



Re: Re: Color for buttons -
Apostolos Michaloudis
28 Posts

Thank you very much!
Happy new year to everyone!



OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book