How to vertically align text and image above a JRadioButton?

只愿长相守 提交于 2019-12-12 02:35:10

问题


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.


回答1:


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.




回答2:


JRadioButton radioB = new JRasioButton (...);

radioB.setVerticalTextPosition(JLabel.BOTTOM);


来源:https://stackoverflow.com/questions/8669735/how-to-vertically-align-text-and-image-above-a-jradiobutton

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