• Post Reply Bookmark Topic Watch Topic
  • New Topic

GroupLayout Help  RSS feed

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create 3 columns with grouplayout. I cannot seem to get the alignment to work. I want the 1st on the left of the JPanel, the 2nd in the center and the 3rd on the right. Can someone point out what I am doing wrong? TIA.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding all the components in single line without the alignment. The components should add from left to right.

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks but in a previous question I was advised not to do it that way. In any case the problem is not that the columns are not sequential, the problem is that they are not evenly spaced across the JPanel. They are sequentially right justified based on the size of each. I thought that is what the alignment parameters are supposed to do but they don't seem to work.
 
Rob Camick
Ranch Hand
Posts: 2828
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you ask a question post a proper SSCCE not just a few random lines of code.

Why are you even playing with a GroupLayout? This is typically used only by IDE's that are forced to use a single layout manager because an IDE can't break the interface into logical sections of the GUI with each section using an appropriate layout manager.

you should first learn the other base layout managers. A GridBagLayout would be far easier to use to create a grid layout.

But if you need help then start with the working examples from the Swing tutorial on A GroupLayout Example. Download the working code and then modify the working code to meet your requirements.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not random code but the specific segment that is giving me trouble. I didn't create an SSCCE because it would take longer to do that than to debug this little bit.

I'm using GroupLayout based on advice that at my skill level GridBagLayout is too complex and over-kill for what I want to do. I've read a little on GridBagLayout and agree with the advice.

I started this code from an example and tried to modify it to suit my needs. It didn't work for me so that is why I'm posting this question.

In any case none of this peripheral response addressed my real question. Are the alignment parameters I'm using supposed to work as I described?
 
Rob Camick
Ranch Hand
Posts: 2828
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not random code but the specific segment that is giving me trouble.


Until a problem is solved you don't know what is or isn't relevant to the problem. We need to know the context of how the code is used.

I didn't create an SSCCE because it would take longer to do that than to debug this little bit.


But you are not debugging the code. You are asking us to debug the code for you. If you want the help then you need to provide us with the code that demonstrates the problem so we can make sure you are using the code correctly.

I'm using GroupLayout based on advice that at my skill level GridBagLayout is too complex and over-kill for what I want to do.


The opposite is true. GroupLayout is more complicated than GridBagLayout because with the GroupLayout you need to set both the horizontal and vertical constraints. A 3 column grid is simple using a GridBagLayout.


I want the 1st on the left of the JPanel, the 2nd in the center and the 3rd on the right.


The easiest solution would be to use a BoxLayout with "glue" between each component. The Swing tutorial on "How to Use BoxLayout" has an example with the component on the right.

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. It wouldn't be the first time I've gotten bad advice. One of the plights of being a noob. I was not aware of BoxLayout as it never came up in my searches. Catch-22. I need to know what is available in order to select it but I can't select what I don't know is available.
 
Paul Clapham
Sheriff
Posts: 22843
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Putnam wrote:I need to know what is available in order to select it but I can't select what I don't know is available.


Then it would be a good idea to go through Oracle's layout manager tutorial: https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

That tutorial at least covers all of the built-in layout managers (including BoxLayout). Other people have written other kinds of layout managers and published them as open source, and there's some good stuff there too, but knowing about the basic Oracle varieties is a good start.
 
Rob Camick
Ranch Hand
Posts: 2828
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to know what is available in order to select it but I can't select what I don't know is available


Comments like that really frustrate me.

I gave you a link to the Swing tutorial on Layout Managers in one of your previous questions: http://www.coderanch.com/t/665759/GUI/java/JPanel

The reason I give a link to the tutorial is so that you have a reference to learn from.

There are working examples of all the basic layout manager you can download and experiment with to get a basic idea what they do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!