2

I am trying to match the following

image pane

while implementing a GridBagLayout. The GBL is the only way I know i can get the different sized elements. I know I can do something like the above picture but I don't know how to do it with GBL. I am also ready to take suggestions on a better idea.

Matthew Kemnetz
  • 845
  • 1
  • 15
  • 28
  • 2
    BTW - for tips on making great screen-shots, see [How do I create screenshots?](http://meta.stackexchange.com/questions/99734/how-do-i-create-a-screenshot-to-illustrate-a-post) – Andrew Thompson Dec 04 '11 at 07:30

2 Answers2

3

See How to Use BoxLayout, maybe with some filler and a nice beveled Border.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
3

Player GUI

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

class PlayerGui {

    public static void main(String[] args) {
        JPanel gui = new JPanel(new BorderLayout());
        gui.setBorder(new BevelBorder(BevelBorder.RAISED));

        JPanel north = new JPanel(new GridLayout(0,1,5,5));
        north.add(new JLabel("Player Name", SwingConstants.CENTER));

        JPanel tfConstrain = new JPanel(new FlowLayout(FlowLayout.CENTER));
        tfConstrain.add(new JTextField(18));

        north.add(tfConstrain);

        gui.add(north, BorderLayout.NORTH);

        JPanel center = new JPanel(new GridLayout(0,1,10,10));
        center.add(new JButton("On This Machine"));
        center.add(new JButton("Netowrk Based"));
        center.add(new JButton("Main Menu"));
        center.setBorder(new EmptyBorder(40,70,40,70));

        gui.add(center, BorderLayout.CENTER);

        JOptionPane.showMessageDialog(null, gui);
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Please also consider using a `BoxLayout` as outlined by trashgod. I just tend to reach to my regular 'bag of tricks' when doing layouts and use a nested layout (putting layouts inside other layouts). Quite lazy of me. ;) – Andrew Thompson Dec 04 '11 at 07:56