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?
> 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.
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();
}
}
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;
}
> 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.