Example usage for java.awt GridLayout GridLayout

List of usage examples for java.awt GridLayout GridLayout

Introduction

In this page you can find the example usage for java.awt GridLayout GridLayout.

Prototype

public GridLayout(int rows, int cols, int hgap, int vgap) 

Source Link

Document

Creates a grid layout with the specified number of rows and columns.

Usage

From source file:FontDemoLabel.java

public FontDemoLabel() {
    super("Font Demo - Label");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = getContentPane();

    // get font name list
    fl = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    // IGNORE the setLayout and North/South stuff...
    // we will discuss it in a few pages!

    cp.setLayout(new BorderLayout());
    cp.add(BorderLayout.NORTH, new Label("Number of Fonts = " + fl.length, Label.CENTER));
    cp.add(BorderLayout.CENTER, p = new JPanel());
    p.setLayout(new GridLayout(5, 0, 5, 5));

    for (int i = 0; i < fl.length; i++) {
        JLabel lab;//from   ww  w  .  jav a  2 s  .c o m

        // The crux of the matter: for each font name,
        // create a label using the name as the text,
        // AND set the font to be the named font!
        p.add(lab = new JLabel(fl[i]));
        lab.setFont(new Font(fl[i], Font.ITALIC | Font.BOLD, 14));
    }
    pack();
}

From source file:com.game.ui.views.PlayerEditor.java

public void doGui() {
    //        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new GridBagLayout());
    GridBagConstraints c1 = new GridBagConstraints();
    c1.fill = GridBagConstraints.NONE;
    c1.anchor = GridBagConstraints.WEST;
    c1.insets = new Insets(10, 5, 10, 5);
    c1.weightx = 0;//  w  w  w .  j  a v  a  2 s  . c o m
    c1.weighty = 0;
    JLabel noteLbl = new JLabel("Pls select a value to choose a Player or you can create a new "
            + "Player entity below. Once selected a Player character, its' details will be available below");
    add(noteLbl, c1);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (GameCharacter character : GameBean.playerDetails) {
        model.addElement(((Player) character).getType());
    }
    c1.gridy = 1;
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(comboBox, c1);
    JPanel wrapperPanel = new JPanel(new GridLayout(1, 2, 10, 10));
    wrapperPanel.setBorder(LineBorder.createGrayLineBorder());
    leftPanel = new JPanel();
    leftPanel.setAlignmentX(0);
    leftPanel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel enemyDtlLbl = new JLabel("Enemy Character Details : ");
    enemyDtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    leftPanel.add(enemyDtlLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    leftPanel.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    leftPanel.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel imageLbl = new JLabel("Image Path : ");
    leftPanel.add(imageLbl, c);
    c.gridx = 1;
    JTextField image = new JTextField("");
    image.setColumns(20);
    leftPanel.add(image, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel healthLbl = new JLabel("Health Pts : ");
    leftPanel.add(healthLbl, c);
    c.gridx = 1;
    JTextField health = new JTextField("");
    health.setColumns(20);
    leftPanel.add(health, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    leftPanel.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    leftPanel.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    JLabel armoursPtsLbl = new JLabel("Armour Points : ");
    leftPanel.add(armoursPtsLbl, c);
    c.gridx = 1;
    JTextField armourPts = new JTextField("");
    armourPts.setColumns(20);
    leftPanel.add(armourPts, c);
    c.gridx = 0;
    c.gridy = 6;
    JLabel attackRngeLbl = new JLabel("Attack Range : ");
    leftPanel.add(attackRngeLbl, c);
    c.gridx = 1;
    JTextField attackRnge = new JTextField("");
    attackRnge.setColumns(20);
    leftPanel.add(attackRnge, c);
    c.gridx = 0;
    c.gridy = 7;
    JLabel movementLbl = new JLabel("Movement : ");
    leftPanel.add(movementLbl, c);
    c.gridx = 1;
    JTextField movement = new JTextField("");
    movement.setColumns(20);
    leftPanel.add(movement, c);
    c.gridx = 0;
    c.gridy = 8;
    JLabel typeLbl = new JLabel("Type : ");
    leftPanel.add(typeLbl, c);
    c.gridx = 1;
    JTextField typeTxt = new JTextField("");
    typeTxt.setColumns(20);
    leftPanel.add(typeTxt, c);
    c.gridx = 0;
    c.gridy = 9;
    JLabel weaponLbl = new JLabel("Equipped Weapon : ");
    leftPanel.add(weaponLbl, c);
    c.gridx = 1;
    DefaultComboBoxModel weapon = new DefaultComboBoxModel();
    for (Item item : GameBean.weaponDetails) {
        if (item instanceof Weapon) {
            weapon.addElement(((Weapon) item).getName());
        }
    }
    JComboBox weaponDrpDown = new JComboBox(weapon);
    weaponDrpDown.setSelectedIndex(-1);
    weaponDrpDown.setMaximumSize(new Dimension(100, 30));
    leftPanel.add(weaponDrpDown, c);
    c.gridx = 0;
    c.gridy = 10;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    leftPanel.add(submit, c);
    wrapperPanel.add(leftPanel);
    lvlPanel = new LevelPanel(true, null);
    wrapperPanel.add(lvlPanel);
    c1.gridy = 2;
    c1.fill = GridBagConstraints.BOTH;
    add(wrapperPanel, c1);
    c1.fill = GridBagConstraints.NONE;
    validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    c1.gridy = 3;
    add(validationMess, c1);
    c1.weightx = 1;
    c1.fill = GridBagConstraints.BOTH;
    c1.weighty = 1;
    c1.gridy = 4;
    add(new JPanel(), c1);
}

From source file:jamel.gui.JamelWindow.java

/**
 * Returns the main panel./*from w  w w  . j  av a 2 s  . c om*/
 * @return the main panel.
 */
private static Component getMainPanel() {
    final JPanel panel = new JPanel(new GridLayout(3, 3, 10, 10));
    panel.add(new Prices());
    panel.add(new FinalGoodsMarket());
    panel.add(new InventoryVolumeFinal());

    panel.add(new Wages());
    panel.add(new BeveridgeCurve());
    panel.add(new BankRatios());

    panel.add(new InflationUnemployment());
    panel.add(new PhillipsCurve());
    panel.add(new Distribution());
    //panel.add(new LaborMarket());
    //panel.add(new Income());
    return panel;
}

From source file:com.intuit.tank.tools.debugger.SelectDialog.java

/**
 * @param arg0//from  w  w w  .  j a v a  2 s .  c  o m
 */
public SelectDialog(Frame f, List<SELECTION_TYPE> items, String itemType, boolean singleSelection) {
    super(f, true);
    setLayout(new BorderLayout());
    this.items = items;
    filterField = new JTextField();
    filterField.addKeyListener(new KeyHandler());
    list = new JList(items.toArray());
    list.setSelectionMode(singleSelection ? ListSelectionModel.SINGLE_SELECTION
            : ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            okBT.setEnabled(list.getSelectedIndex() != -1);
        }
    });
    list.addMouseListener(new MouseAdapter() {

        /**
         * @{inheritDoc
         */
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                select();
            }
        }

    });
    JPanel labelPanel = new JPanel(new GridLayout(singleSelection ? 1 : 2, 1, 0, 5));
    labelPanel.add(new JLabel("Select a " + itemType + "."));
    if (!singleSelection) {
        String key = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1 ? "" : "control";
        System.out.println(key);
        labelPanel.add(new JLabel("Hold down the " + key + " key to select multiple " + itemType + "."));
    }
    add(labelPanel, BorderLayout.NORTH);
    JScrollPane sp = new JScrollPane(list);
    JPanel centerPanel = new JPanel(new BorderLayout());
    centerPanel.add(filterField, BorderLayout.NORTH);
    centerPanel.add(sp, BorderLayout.CENTER);
    add(centerPanel, BorderLayout.CENTER);
    add(createButtonPanel(), BorderLayout.SOUTH);
    setSize(new Dimension(400, 500));
    setBounds(new Rectangle(getSize()));
    setPreferredSize(getSize());
    WindowUtil.centerOnParent(this);
}

From source file:gui.TraitViewerDialog.java

private JPanel createButtons() {
    bClose = new JButton("Close");
    bClose.addActionListener(this);

    JPanel p1 = new JPanel(new GridLayout(1, 1, 5, 5));
    p1.add(bClose);/*from   w w  w .  jav  a 2 s . c  o m*/

    JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
    p2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    p2.add(p1);

    return p2;
}

From source file:com.googlecode.vfsjfilechooser2.accessories.DefaultAccessoriesPanel.java

private void initComponents() {
    buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(0, 1, 3, 3));

    Action action;/* w  w  w. j a  v  a 2s  .  c om*/

    action = new ManageBookmarksAction(VFSResources.getMessage("VFSJFileChooser.bookmarksLabelText"),
            getIcon("book.png"));
    bookmarksButton = new JButton(action);
    bookmarksButton.setHorizontalAlignment(SwingConstants.LEFT);

    action = new ConnectionWizardAction(VFSResources.getMessage("VFSJFileChooser.connectionButtonText"),
            getIcon("connect.png"));
    connectionsButton = new JButton(action);
    connectionsButton.setHorizontalAlignment(SwingConstants.LEFT);

    action = new LocalFilesAction(VFSResources.getMessage("VFSJFileChooser.localFilesButtonText"),
            getIcon("drive.png"));
    localFSButton = new JButton(action);
    localFSButton.setHorizontalAlignment(SwingConstants.LEFT);

    buttonsPanel.add(bookmarksButton);
    buttonsPanel.add(Box.createVerticalStrut(20));
    buttonsPanel.add(connectionsButton);
    buttonsPanel.add(Box.createVerticalStrut(20));
    buttonsPanel.add(localFSButton);

    add(buttonsPanel, BorderLayout.NORTH);
    add(new JPanel(), BorderLayout.CENTER);

    final Frame c = (Frame) SwingUtilities.getWindowAncestor(fileChooser);

    bookmarksDialog = new BookmarksDialog(c, fileChooser);

    connectionDialog = new ConnectionDialog(c, bookmarksDialog, fileChooser);
}

From source file:MainClass.java

public MainClass() {
    super();/*w w  w .  ja va  2  s. c  o m*/

    setChannel(currentNumber);

    numberLabel.setHorizontalAlignment(JLabel.CENTER);
    numberLabel.setFont(new Font("Serif", Font.PLAIN, 32));

    getContentPane().add(numberLabel, BorderLayout.NORTH);

    JPanel buttonPanel = new JPanel(new GridLayout(2, 2, 16, 6));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(6, 16, 16, 16));
    getContentPane().add(buttonPanel, BorderLayout.CENTER);
    buttonPanel.add(new JButton(upAction));
    buttonPanel.add(new JButton(gotoFavoriteAction));
    buttonPanel.add(new JButton(downAction));
    buttonPanel.add(new JButton(setFavoriteAction));

    JMenuBar mb = new JMenuBar();
    JMenu menu = new JMenu("Number");
    menu.add(new JMenuItem(upAction));
    menu.add(new JMenuItem(downAction));
    menu.addSeparator();
    menu.add(new JMenuItem(gotoFavoriteAction));
    menu.add(new JMenuItem(setFavoriteAction));
    mb.add(menu);
    setJMenuBar(mb);
}