Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

radiobuttons changing background color

 
Craig Parsons
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Craig Parsons
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
That was driving me crazy. Now it looks so obvious. I'll check out that tutorial too. Thanks again for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic