How to vertically align text and image above a JRa

2019-08-27 19:46发布

Is it possible to align both the text and image above the JRadioButton icon?

Edit -
Well, apparently setting the icon in the constructor actually replaces the default JRadioButton icon, which I wasn't expecting. Looks like I may have to use two separate components and throw them into the same container.

2条回答
forever°为你锁心
2楼-- · 2019-08-27 20:12

This will set the text above the JRadioButton:

radiobutton.setHorizontalTextPosition(SwingConstants.CENTER);
radiobutton.setVerticalTextPosition(JRadioButton.TOP);

And yes, using the setIcon method replaces the JRadioButton icon.

查看更多
【Aperson】
3楼-- · 2019-08-27 20:16
JRadioButton radioB = new JRasioButton (...);

radioB.setVerticalTextPosition(JLabel.BOTTOM);
查看更多
登录 后发表回答