Search code examples
javacolorslook-and-feelpaintcomponent

Draw round Button in LookAndFeel-Style


I'm experimenting with JRadioButton's to put them on a JToolbar and select the last one clicked. If i'd use JButtons they wouldn't keep the Selection.

Since JRadioButton always have that Dot, I need to draw them myself by overriding the paint-methods.

The Button's will be circles with an Icon in it. That works if I draw Images, but looks aweful. The problem I have is that I would like to draw the circle so that these Buttons always look like the JButtons with the current LookAndFeel.

How can i do that? I searched for a while now, but I didn't find methods to read some default-colors of the LookAndFeel which I could use.

So how can i read Background-Colors etc. of the current LookAndFeel to use it for some custom Button-Drawing?


Solution

  • So how can i read Background-Colors etc. of the current LookAndFeel to use it for some custom Button-Drawing?

    See UIManager Defaults.

    I need to draw them myself by overriding the paint-methods

    Don't do custom painting in the component. If you don't like the default Icons, then create your own Icon and do the custom painting there or create an Image and use an ImageIcon. The you can use the setXXXIcon() methods.