2

When any Radio Button in my Java UI program is selected, the selection is shown by a black dot. I want to make it Green. I'm using Java Swing. I followed the answer given to this SO Question , but it's not working for me. It still shows a black dot when selected.

public class OptionFrame extends JFrame {
 
     public OptionFrame(){
            UIManager.put("RadioButton.focus", new ColorUIResource(Color.GREEN));
            SwingUtilities.updateComponentTreeUI(this);
     }
}

I'm unable to understand why above code is not working. Any suggestions are highly appreciated.

Thanks.

Community
  • 1
  • 1
sanjeev mk
  • 4,276
  • 6
  • 44
  • 69
  • Change foreground color, instead of focus color. – Mordechai Jan 18 '13 at 19:39
  • possible duplicate of [can't set JPanel color and JRadioButton invisibility](http://stackoverflow.com/questions/14085840/cant-set-jpanel-color-and-jradiobutton-invisibility). – trashgod Jan 18 '13 at 19:49
  • Nope, still doesn't work. – sanjeev mk Jan 18 '13 at 19:50
  • possible opportunity for [JRadioButton: how to replace text by IconImage?](http://stackoverflow.com/q/6774987/230513). – trashgod Jan 18 '13 at 19:50
  • @trashgod , No, this is different from the question you posted. Background color affects the area around the radio buttons, and IconImage only adds an icon to the side of the radio button. Only other similar question is the one I have posted in my question. – sanjeev mk Jan 18 '13 at 19:53
  • @sanjeevmk: I've tried to explain below. – trashgod Jan 18 '13 at 20:11

1 Answers1

2

I'm unable to understand why above code is not working.

As discussed here, the appearance is controlled by the Look & Feel dependent UI delegate. The delegate is free to render the dot however it pleases; some ignore the defaults and delegate to a host platform component. Short of writing your own ButtonUI, replacing the Icon is the next best thing. This example illustrates the effect for the selected state of JToggleButton, the parent of JRadioButton. ColorIcon, seen here, is also handy in this context, and more examples are seen here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045