File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes radiobuttons changing background color Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "radiobuttons changing background color" Watch "radiobuttons changing background color" New topic
Author

radiobuttons changing background color

Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
I have 4 radio buttons in a group box. When the user selects any one, the background color should change to whatever color is associated with the radio button. I have it coded but here is my problem. When the radio button is checked the color checked flashes and then goes away. The same thing happens when any of the 4 buttons is checked.
Any Suggestions?
Thanks,
saager mhatre
Ranch Hand

Joined: Dec 20, 2000
Posts: 61
I think we're definitely going to need a few specifics on this.
Some code would be good. If not, atleast let us know if you're using Swing or AWT and what event are you handling to change the BGColor as also how you're changing it.
See ya soon
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
Here are some pieces of the code. The entire program would be too large to paste in this forum. I hope everything is here that would be needed to see if there is a problem. These buttons get created and added to a box layout. That box layout gets add to west section of a border layout.

Thanks,
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Welcome to the Ranch Craig.
set the background to the content pane of the JFrame by
getContentPane().setBackground(color);
The blue button was not given listener. The gray button was not added to the ButtonGroup


SCJP2. Please Indent your code using UBB Code
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
I added those changes and know the background doesn't even flash the color. I am kind of new to all this and a bit confused. I have added my entire code hoping for a little help. The code is still a work in progress and nees a lot work to dress it up. I have also commented out several lines of code for my testing.
The only area I am concerned about is how the radio buttons can change the background color of my application.
If anyone can help it would be appreciated.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
The container is behind the JPanels you placed on the different regions of the BorderLayout. Thus if you set its color you will not see any change. Set the color of westPanel, eastPanel etc.
You might also have a look at How to write an ItemListener in the Java Tutorial.
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
Thanks,
That was driving me crazy. Now it looks so obvious. I'll check out that tutorial too. Thanks again for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: radiobuttons changing background color
 
Similar Threads
new window
Changing the content of HTML dynamically from a JSP
radio buttons selection
Images on Applet?
radio button using javascript DOM