Is there a Vertical FlowLayout?

Is there a Vertical Flow Layout or can you set Box Layout to not respace when the window is resized?
[107 byte] By [terek_olsona] at [2007-11-27 1:14:43]
# 1

So by default you want the components to be placed vertically, but if there isn't enough vertical room, the components should wrap to the next vertical column?

If you use BoxLayout(Y_AXIS) the components will appear vertically.

> to not respace when the window is resized?

What is respacing?

rkippena at 2007-7-11 23:50:03 > top of Java-index,Desktop,Core GUI APIs...
# 2

> So by default you want the components to be placed

> vertically,

Yes I want the components to be placed vertically.

>but if there isn't enough vertical room,

>the components should wrap to

>the next vertical column?

There are not enough components to wrap to the next "column". I am also going to put a scroll on side and bottom.

> What is respacing?

When I resize the frame with BoxLayout, the items spread out for an equal amount of space between them.

I am looking for something like:

displayUserId.setLayout(new FlowLayout(FlowLayout.[b]TOP[/b]));

But if BoxLayout is my option, is there a way to disable the spreading out of the different components when the window size is increased. I know some people would say just lock the windows size, but it is not an option.

terek_olsona at 2007-7-11 23:50:04 > top of Java-index,Desktop,Core GUI APIs...
# 3

No idea what you're talking about.

This example all the components stay at the top:

import javax.swing.*;

import java.awt.*;

public class BTest extends JPanel {

public BTest() {

LayoutManager m = new BoxLayout(this, BoxLayout.Y_AXIS); // boxlayout is stupid

setLayout(m);

add(new JButton("button1"));

add(new JButton("button2"));

}

public static void main(String[] args) {

JFrame f = new JFrame();

f.setContentPane(new BTest());

f.pack();

f.show();

}

}

rkippena at 2007-7-11 23:50:04 > top of Java-index,Desktop,Core GUI APIs...
# 4
I am having an issue because I have 5 components, (3 panels and 2 buttons) The 2 buttons work as you say, but the panels are spreading out as the window size changes.Is there a way to get the minimum size for the panels and hold that size?
terek_olsona at 2007-7-11 23:50:04 > top of Java-index,Desktop,Core GUI APIs...
# 5
> but the panels are spreading out as the window size changes.Did you set the maximum size of the panel equal to the preferred size?
camickra at 2007-7-11 23:50:04 > top of Java-index,Desktop,Core GUI APIs...
# 6

Yes I have captured the preferredSize and set it.

below is the code that generates the screen. The methods displayCurrentUser, displayUserID, and displayPassword() are the panels that consist of other components.

public JPanel displayPanel()

{

displayLoginPanel=new JPanel();

displayLoginPanel.setLayout(new BoxLayout(displayLoginPanel,BoxLayout.Y_AXIS));

displayLoginPanel.add(displayCurrentUser());

displayLoginPanel.add(displayUserId());

displayLoginPanel.add(displayPassword());

loginButton=new JButton("Login");

logoutButton=new JButton("Logout");

displayLoginPanel.add(loginButton);

displayLoginPanel.add(logoutButton);

loginButton.addActionListener(loginHandler);

logoutButton.addActionListener(loginHandler);

Dimension x = displayCurrentUser.getPreferredSize();

displayCurrentUser.setSize(x);

x=displayUserId.getPreferredSize();

displayUserId.setSize(x);

x=displayPassword.getPreferredSize();

displayPassword.setSize(x);

return displayLoginPanel;

}

terek_olsona at 2007-7-11 23:50:04 > top of Java-index,Desktop,Core GUI APIs...
# 7
FYI - In the above code the panel names are the same as the method names.
terek_olsona at 2007-7-11 23:50:04 > top of Java-index,Desktop,Core GUI APIs...
# 8

> Yes I have captured the preferredSize and set it.

That not what I asked.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.

camickra at 2007-7-11 23:50:04 > top of Java-index,Desktop,Core GUI APIs...
# 9
Thank you, I appreciate the help. I understand now. Get preferred then set it as the maximum.
terek_olsona at 2007-7-11 23:50:04 > top of Java-index,Desktop,Core GUI APIs...