0

I have sever JPanels which have to be ordered vertically. For that I want to fix the width 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).

Roman
  • 124,451
  • 167
  • 349
  • 456
  • 1
    This is your second question on this topic. It is still not clear. If you want real help then post your SSCCE: http://sscce.org. Otherwise all the answers will say "read the Swing tutorial on Using Layout Managers", because you question does not have nearly enough information to provide a custom answer. You've asked enough question in the forum you should know this by now. – camickr Mar 29 '10 at 14:57
  • @camickr, I posted the code: http://stackoverflow.com/questions/2536873/how-can-i-set-size-of-a-button – Roman Mar 29 '10 at 15:00
  • 1
    Not for this question you didn't. So you are saying you actuallyhave 3 postings on this topic? We are not going to search all over the forum guessing that you might have posted code on some other "double post". All the information should be located in one posting so everybody knows what has been asked and suggested. If you don't get an answer in your first posting its because you don't ask a clear, understandable question and there is no reason to clutter the forums by asking another question. Learn to ask a question properly the first time. – camickr Mar 29 '10 at 15:35
  • @camickr, it would be easier if you say what exactly is not clear to you. Then I can be more clear. But if you just complains saying that "it's not clear", then I cannot help because I cannot read thoughts. I think that my question is clear and I do not know why it is not clear to you (because you do not tell me that). I do not know why. Either it is a secret or, may be, you just do not know what is not clear to you? – Roman Mar 29 '10 at 15:42
  • 1
    No, it is not my job to continually ask for you to clarify your question. You should get it correct the first time so there is no need for multiple postings. Part of posting a clear question is to post a SSCCE so we can execute the code when your verbal description is lacking. Since you have 3 posting on the topic obviously the question is NOT clear, since using layout managers is easy when the requirement is fully understood. And since you continue NOT to accept previous answers, I am not about to go out of my way to make an effort to help you. You get what you give. – camickr Mar 29 '10 at 15:58

1 Answers1

1

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".

Community
  • 1
  • 1
Nivas
  • 18,126
  • 4
  • 62
  • 76
  • I am trying to hand code. I also tried to use the Grid Layout but as any other layout it adopt the size of the window and change proportions of its elements (relation between width and heights of included elements). For example, I also could use vertical ordering using border layout but then I have the same problem: it change proportion of the included elements. – Roman Mar 29 '10 at 14:37