views:

788

answers:

4

Hey everyone. I'm trying to make a swing GUI with a button and a label on it. im using a border layout and the label ( in the north field ) shows up fine, but the button takes up the rest of the frame (it's in the center field). any idea how to fix this?

A: 

Use BoxLayout.

k0sh
+4  A: 
OscarRyz
What's the default LayoutManger on the Panel then? FlowLayout?
Allain Lalonde
FlowLayout, that's correct.
OscarRyz
A: 

awsome! thanks alot.

Michael Hoyle
A: 

Again :)


    import javax.swing.*;

    public class TestFrame extends JFrame {
        public TestFrame() {
            JLabel label = new JLabel("Some info");
            JButton button = new JButton("Ok");
            Box b = new Box(BoxLayout.Y_AXIS);
            b.add(label);
            b.add(button);
            getContentPane().add(b);

        }
        public static void main(String[] args) {
            JFrame f = new TestFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setLocationRelativeTo(null);
            f.setVisible(true);

        }
    }
k0sh