开发者

Can I fix the width of JRadioButton?

I have sever JPanels which have to be ordered vertically. For that I want to fix the wi开发者_如何学运维dth of the JPanels. Because if they are too short in comparison with the windows width, they will go horizontally (one after another) and I do not want it. At the moment the width of the JPanel is not constant because the width of the JRadioButton (included into JPabel) is not constant. How can I make the width of the JRadioButton constant? At the moment it is not constant because of the label (which can be different).


If the aim is laying out panels in a particular fashion, you must be using a LayoutManager, rather than thinking of resizing indivudual components just for the layout. By default swing uses FlowLayout, and thats why your panels are falling one after another as long as there is space in the "line" (and then they would flow to the next line)

Try using GridBagLayout, its not as complex as may tutorials/articles say. The one or two hours you spend learning this will be a great help. It would help you to arrange your components is a very flexible manner.

Btw, how are you developing your UIs? If you are using a IDE (Eclipse+plugins or NetBeans) then the IDE should help you do the laying out (say, via GroupLayout).

If you are trying to hand code the GUI, then GridBagLayout is the best way to get "in control".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜