swingiconsalignmentjradiobutton

Vertical alignment of icons with various size in JRadioButtonMenuItem


I met problem to align icons of different sizes with JRadioButtonMenuItem. Here's a picture of my problem. The icons have several sizes and are left aligned.

The icons have several sizes and are left aligned

I would like to center the icons as in the picture below.

enter image description here

Apparently, none of the methods of JRadioButtonMenuItem class allow to do that...


Solution

  • As an alternative, implement the Icon interface using a constant enclosing size and scale the rendered content to reflect the desired image size, as shown in this example. For convenience, you can render arbitrary sized unicode glyphs, as shown here.

    image