Example usage for javax.swing GroupLayout GroupLayout

List of usage examples for javax.swing GroupLayout GroupLayout

Introduction

In this page you can find the example usage for javax.swing GroupLayout GroupLayout.

Prototype

public GroupLayout(Container host) 

Source Link

Document

Creates a GroupLayout for the specified Container .

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);//  www  .java 2s .  co m

    JButton buttonD = new JButton("D");
    JButton buttonR = new JButton("R");
    JButton buttonY = new JButton("Y");
    JButton buttonO = new JButton("O");
    JButton buttonT = new JButton("T");

    GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup();

    leftToRight.addComponent(buttonD);
    GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup();
    columnMiddle.addComponent(buttonR);
    columnMiddle.addComponent(buttonO);
    columnMiddle.addComponent(buttonT);
    leftToRight.addGroup(columnMiddle);
    leftToRight.addComponent(buttonY);

    GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup();
    GroupLayout.ParallelGroup rowTop = layout.createParallelGroup();
    rowTop.addComponent(buttonD);
    rowTop.addComponent(buttonR);
    rowTop.addComponent(buttonY);
    topToBottom.addGroup(rowTop);
    topToBottom.addComponent(buttonO);
    topToBottom.addComponent(buttonT);

    layout.setHorizontalGroup(leftToRight);
    layout.setVerticalGroup(topToBottom);

    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);/* ww  w  .  ja va  2 s .  c o m*/

    System.out.println(layout.getLayoutStyle());

    JButton buttonD = new JButton("D");
    JButton buttonR = new JButton("R");
    JButton buttonY = new JButton("Y");
    JButton buttonO = new JButton("O");
    JButton buttonT = new JButton("T");

    GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup();

    leftToRight.addComponent(buttonD);
    GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup();
    columnMiddle.addComponent(buttonR);
    columnMiddle.addComponent(buttonO);
    columnMiddle.addComponent(buttonT);
    leftToRight.addGroup(columnMiddle);
    leftToRight.addComponent(buttonY);

    GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup();
    GroupLayout.ParallelGroup rowTop = layout.createParallelGroup();
    rowTop.addComponent(buttonD);
    rowTop.addComponent(buttonR);
    rowTop.addComponent(buttonY);
    topToBottom.addGroup(rowTop);
    topToBottom.addComponent(buttonO);
    topToBottom.addComponent(buttonT);

    layout.setHorizontalGroup(leftToRight);
    layout.setVerticalGroup(topToBottom);

    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);//from   w w  w  .j  a v  a  2 s.c om

    System.out.println(layout.getAutoCreateGaps());

    JButton buttonD = new JButton("D");
    JButton buttonR = new JButton("R");
    JButton buttonY = new JButton("Y");
    JButton buttonO = new JButton("O");
    JButton buttonT = new JButton("T");

    GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup();

    leftToRight.addComponent(buttonD);
    GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup();
    columnMiddle.addComponent(buttonR);
    columnMiddle.addComponent(buttonO);
    columnMiddle.addComponent(buttonT);
    leftToRight.addGroup(columnMiddle);
    leftToRight.addComponent(buttonY);

    GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup();
    GroupLayout.ParallelGroup rowTop = layout.createParallelGroup();
    rowTop.addComponent(buttonD);
    rowTop.addComponent(buttonR);
    rowTop.addComponent(buttonY);
    topToBottom.addGroup(rowTop);
    topToBottom.addComponent(buttonO);
    topToBottom.addComponent(buttonT);

    layout.setHorizontalGroup(leftToRight);
    layout.setVerticalGroup(topToBottom);

    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);//from   w w w . j  a va  2  s . c om

    System.out.println(layout.getHonorsVisibility());

    JButton buttonD = new JButton("D");
    JButton buttonR = new JButton("R");
    JButton buttonY = new JButton("Y");
    JButton buttonO = new JButton("O");
    JButton buttonT = new JButton("T");

    GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup();

    leftToRight.addComponent(buttonD);
    GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup();
    columnMiddle.addComponent(buttonR);
    columnMiddle.addComponent(buttonO);
    columnMiddle.addComponent(buttonT);
    leftToRight.addGroup(columnMiddle);
    leftToRight.addComponent(buttonY);

    GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup();
    GroupLayout.ParallelGroup rowTop = layout.createParallelGroup();
    rowTop.addComponent(buttonD);
    rowTop.addComponent(buttonR);
    rowTop.addComponent(buttonY);
    topToBottom.addGroup(rowTop);
    topToBottom.addComponent(buttonO);
    topToBottom.addComponent(buttonT);

    layout.setHorizontalGroup(leftToRight);
    layout.setVerticalGroup(topToBottom);

    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("GroupLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    GroupLayout groupLayout = new GroupLayout(contentPane);

    contentPane.setLayout(groupLayout);/*from   w  w w.  ja v  a  2s.c  o m*/

    JLabel label = new JLabel("Label");
    JButton b2 = new JButton("Second Button");

    groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup().addComponent(label).addComponent(b2));

    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(label).addComponent(b2));

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("GroupLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    GroupLayout groupLayout = new GroupLayout(contentPane);

    contentPane.setLayout(groupLayout);//from  w  w w.java 2 s  . co  m

    JLabel label = new JLabel("Label");
    JButton b2 = new JButton("Second Button");

    groupLayout.setHorizontalGroup(
            groupLayout.createSequentialGroup().addComponent(label).addGap(5, 10, 50).addComponent(b2));

    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(label).addComponent(b2));

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("GroupLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    GroupLayout groupLayout = new GroupLayout(contentPane);
    groupLayout.setAutoCreateGaps(true);
    groupLayout.setAutoCreateContainerGaps(true);
    contentPane.setLayout(groupLayout);//from  w  ww .j a va2 s  . c o m

    JButton b1 = new JButton("Button 1");
    JButton b2 = new JButton("Button Second");
    JButton b3 = new JButton("3");
    JButton b4 = new JButton("4");

    groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup()
            .addGroup(groupLayout.createParallelGroup(LEADING).addComponent(b1).addComponent(b3))
            .addGroup(groupLayout.createParallelGroup(TRAILING).addComponent(b2).addComponent(b4)));

    groupLayout.setVerticalGroup(groupLayout.createSequentialGroup()
            .addGroup(groupLayout.createParallelGroup(BASELINE).addComponent(b1).addComponent(b2))
            .addGroup(groupLayout.createParallelGroup(BASELINE).addComponent(b3).addComponent(b4)));

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public Main() {
    Container pane = getContentPane();
    GroupLayout gl = new GroupLayout(pane);
    pane.setLayout(gl);/*from w ww.j a v  a 2 s .c  o m*/

    JLabel avLbl = new JLabel("Available");
    JLabel tagsLbl = new JLabel("Tags");
    JLabel selLbl = new JLabel("Selected");

    JButton newBtn = new JButton("New");
    JButton moveBtn = new JButton(">>");
    JButton remBtn = new JButton("Remove");

    JList leftList = new JList();
    JScrollPane spleft = new JScrollPane(leftList);
    JList rightList = new JList();
    JScrollPane spright = new JScrollPane(rightList);

    gl.setAutoCreateGaps(true);
    gl.setAutoCreateContainerGaps(true);

    gl.setHorizontalGroup(gl.createParallelGroup(CENTER).addComponent(tagsLbl)
            .addGroup(gl.createSequentialGroup()
                    .addGroup(gl.createParallelGroup(CENTER).addComponent(avLbl)
                            .addComponent(spleft, 100, 200, Short.MAX_VALUE).addComponent(newBtn))
                    .addComponent(moveBtn).addGroup(gl.createParallelGroup(CENTER).addComponent(selLbl)
                            .addComponent(spright, 100, 200, Short.MAX_VALUE).addComponent(remBtn))));
    gl.setVerticalGroup(gl.createSequentialGroup().addComponent(tagsLbl)
            .addGroup(gl.createParallelGroup(CENTER)
                    .addGroup(gl.createSequentialGroup().addComponent(avLbl)
                            .addComponent(spleft, 100, 250, Short.MAX_VALUE).addComponent(newBtn))
                    .addComponent(moveBtn).addGroup(gl.createSequentialGroup().addComponent(selLbl)
                            .addComponent(spright, 100, 250, Short.MAX_VALUE).addComponent(remBtn))));
    pack();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

private JPanel create() {
    JPanel panel = new JPanel();
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);//w w w .ja  va2s . c o m
    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);
    GroupLayout.ParallelGroup parallel = layout.createParallelGroup();
    layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(parallel));
    GroupLayout.SequentialGroup sequential = layout.createSequentialGroup();
    layout.setVerticalGroup(sequential);
    for (int i = 0; i < NUM; i++) {
        labels[i] = new JLabel(String.valueOf(i + 1), JLabel.RIGHT);
        fields[i] = new JTextField(String.valueOf("" + (i + 1)));
        labels[i].setLabelFor(fields[i]);
        parallel.addGroup(layout.createSequentialGroup().addComponent(labels[i]).addComponent(fields[i]));
        sequential.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(labels[i])
                .addComponent(fields[i]));
        layout.linkSize(SwingConstants.HORIZONTAL, labels[i], labels[0]);
    }
    return panel;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container pane = getContentPane();
    GroupLayout gl = new GroupLayout(pane);
    pane.setLayout(gl);/* w w w .j a v  a  2 s .  c o m*/

    gl.setAutoCreateGaps(true);
    gl.setAutoCreateContainerGaps(true);

    JButton btn = new JButton("Switch");
    btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 1; i < 9; i++) {
                labels[i].setVisible(!labels[i].isVisible());
            }
        }
    });

    gl.setHonorsVisibility(false);

    SequentialGroup seqGroup = gl.createSequentialGroup();
    gl.setHorizontalGroup(seqGroup);
    seqGroup.addComponent(btn);
    seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10);
    for (int i = 0; i < 10; i++) {
        seqGroup.addComponent(labels[i]);
        seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10);
    }
    ParallelGroup parGroup = gl.createParallelGroup();
    gl.setVerticalGroup(parGroup);
    parGroup.addComponent(btn);

    for (int i = 0; i < 10; i++) {
        parGroup.addComponent(labels[i]);
    }
    pack();
}