Vertical alignment of icons with various size in JRadioButtonMenuItem

浪子不回头ぞ 提交于 2019-12-11 01:58:21

问题


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.

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

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


回答1:


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.




回答2:


Calculate how much white space to add before and after an icon with the width of the widest icon and place each icon with the method setIconTextGap() such that:

[(widestIconWidth-iconWidth)/2_ofWhiteSpace][icon][(widestIconWidth-iconWidth)/2_ofWhiteSpace]


来源:https://stackoverflow.com/questions/12250188/vertical-alignment-of-icons-with-various-size-in-jradiobuttonmenuitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!