I am using FlowLayout and I want my components to be "flow" from the top left of my frame to the bottom right instead of starting in the center of the screen. GridLayout does this fine, but it re-adjusts the size of my components and I don't like that. I would use GridBagLayout but it is so complicated I wanted to see If it is possible to do what I want with FlowLayout.
Asked
Active
Viewed 9,941 times
4
-
that code is difficult to read. I would create a class for the MatrixPanel, since you seem to have three of them, you create one class an instanciate it 3 times. Would make it much easier to understand. – MeBigFatGuy Apr 24 '11 at 07:42
1 Answers
8
You can pass it as parameter to the constructor
new FlowLayout(FlowLayout.LEADING);
Edit: After having the code I recognized that the vertical alignment is your issue. You should switch to another layout to fix this, e.g.:
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.X_AXIS));

Howard
- 38,639
- 9
- 64
- 83
-
Yeah I tried that, I don't know why it isn't working. I have 3 JPanels, 2 of which are the same size, and the other of which is as wide as the other two added together and almost twice as tall. The two smaller JPanels keep showing up in the center of the frame while the the third JPanel does what I would expect it to do. – ubiquibacon Apr 24 '11 at 06:56
-
Then please post a [SSCCE](http://sscce.org/). The issue has to be somewhere else in your layout. – Howard Apr 24 '11 at 06:57
-
you sir are the man. Thanks a lot. Reading up on BoxLayout has been added to my to-do list. – ubiquibacon Apr 24 '11 at 08:09
-
You're welcome. Reading up on layout managers is always worth the time. And they aren't as complicated as on first sight. – Howard Apr 24 '11 at 08:13