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) 

Source Link

Document

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

Usage

From source file:Main.java

protected void createComponents() {
    if (orientation == SwingConstants.VERTICAL) {
        setLayout(new GridLayout(2, 1));
        incrementButton = new BasicArrowButton(SwingConstants.NORTH);
        decrementButton = new BasicArrowButton(SwingConstants.SOUTH);
        add(incrementButton);// w w w  . j  a  v  a2 s  . co  m
        add(decrementButton);
    } else if (orientation == SwingConstants.HORIZONTAL) {
        setLayout(new GridLayout(1, 2));
        incrementButton = new BasicArrowButton(SwingConstants.EAST);
        decrementButton = new BasicArrowButton(SwingConstants.WEST);
        add(decrementButton);
        add(incrementButton);
    }
}

From source file:SliderControlPaintLine.java

public SliderControlPaintLine() {
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new GridLayout(3, 3));
    getContentPane().add(controlPanel, BorderLayout.NORTH);

    JLabel label1 = new JLabel("Translate(dx,dy): ");
    JLabel label2 = new JLabel("Rotate(Theta,ox,oy): ");
    JLabel label3 = new JLabel("Scale(sx,sy)x10E-2:");

    controlPanel.add(label1);//  w  ww .  j  av a2s .  c  om

    slider1 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50);
    slider2 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50);

    controlPanel.add(label2);

    slider3 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 360, 0, 90, 45);

    JPanel subPanel = new JPanel();
    subPanel.setLayout(new GridLayout(1, 2));

    slider4 = createSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50);
    slider5 = createSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50);
    controlPanel.add(subPanel);

    controlPanel.add(label3);

    slider6 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10);
    slider7 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10);

    JPanel widthPanel = new JPanel();
    JLabel label4 = new JLabel("Width Control:", JLabel.RIGHT);
    slider8 = createSlider(widthPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10);
    slider8.addChangeListener(new SliderListener());

    widthPanel.setLayout(new GridLayout(1, 2));
    widthPanel.add(label4);
    widthPanel.add(slider8);
    getContentPane().add(widthPanel, BorderLayout.SOUTH);

    getContentPane().add(canvas);

    setSize(500, 500);
    setVisible(true);
}

From source file:House.java

public House() {
    super(new BorderLayout());
    JPanel controlPanel = new JPanel(new GridLayout(3, 3));
    add(controlPanel, BorderLayout.NORTH);

    controlPanel.add(new JLabel("Translate(dx,dy): "));

    sliderTransX = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50);
    sliderTransY = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50);

    // To control rotation
    controlPanel.add(new JLabel("Rotate(Theta,ox,oy): "));
    sliderRotateTheta = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 360, 0, 90, 45);

    JPanel subPanel = new JPanel();
    subPanel.setLayout(new GridLayout(1, 2));

    sliderRotateX = setSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50);

    sliderRotateY = setSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50);
    controlPanel.add(subPanel);//  w  w w  .j  a  v a2 s .com

    // To control scaling
    controlPanel.add(new JLabel("Scale(sx,sy)x10E-2:"));

    sliderScaleX = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10);

    sliderScaleY = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10);

    // To control width of line segments
    JLabel label4 = new JLabel("Width Control:", JLabel.RIGHT);
    sliderWidth = new JSlider(JSlider.HORIZONTAL, 0, 20, 1);
    sliderWidth.setPaintTicks(true);
    sliderWidth.setMajorTickSpacing(5);
    sliderWidth.setMinorTickSpacing(1);
    sliderWidth.setPaintLabels(true);
    sliderWidth.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            width = sliderWidth.getValue();
            canvas.repaint();
        }
    });
    JPanel widthPanel = new JPanel();
    widthPanel.setLayout(new GridLayout(1, 2));
    widthPanel.add(label4);
    widthPanel.add(sliderWidth);
    add(widthPanel, BorderLayout.SOUTH);

    canvas = new MyCanvas();
    add(canvas, "Center");
}

From source file:CubicCurveMouse.java

public CubicCurveMouse() {
    super();//from   w  w  w  .  ja va 2 s  . c  om
    Container container = getContentPane();

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));

    panel.add(label);
    panel.add(label);

    panel.add(coords);

    container.add(panel, BorderLayout.SOUTH);

    canvas = new DrawingCanvas();
    container.add(canvas);

    addWindowListener(new WindowEventHandler());
    setSize(300, 300);
    setVisible(true);
}

From source file:Main.java

private JPanel createGridPanel() {
    int rows = 5;
    int cols = 5;
    JPanel gridPanel = new JPanel(new GridLayout(rows, cols));
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            JLabel label = new JLabel(String.format("[%d, %d]", i, j), SwingConstants.CENTER);
            label.setBorder(BorderFactory.createEtchedBorder());
            gridPanel.add(label);/*from  w w w . ja  v  a  2 s. c o  m*/
        }
    }
    return gridPanel;
}

From source file:cl.almejo.vsim.gui.actions.preferences.ColorPreferences.java

public ColorPreferences(Component parent) {
    _parent = parent;//from w ww . j  a va 2s  .  c  o m
    setBorder(new EmptyBorder(10, 10, 10, 10));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel pickers = new JPanel();
    pickers.setLayout(new GridLayout(10, 2));

    pickers.add(new Label(Messages.t("preferences.color.scheme.current.label")));
    _comboBox = createSchemeCombobox();
    pickers.add(_comboBox);

    addColorChooser(pickers, "gates");
    addColorChooser(pickers, "background");
    addColorChooser(pickers, "bus-on");
    addColorChooser(pickers, "ground");
    addColorChooser(pickers, "off");
    addColorChooser(pickers, "wires-on");
    addColorChooser(pickers, "signal");
    addColorChooser(pickers, "grid");
    addColorChooser(pickers, "label");
    add(pickers);

    JPanel buttons = new JPanel();
    JButton button = new JButton(Messages.t("preferences.color.scheme.save.label"));
    buttons.add(button);
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                FileUtils.writeStringToFile(new File("colors.json"), ColorScheme.save());
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    });
    button = new JButton(Messages.t("preferences.color.scheme.new.label"));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String themeName = JOptionPane.showInputDialog(Messages.t("color.scheme.dialog.new.title"), "");
            if (themeName != null) {
                while (ColorScheme.exists(themeName)) {
                    JOptionPane.showMessageDialog(_parent,
                            Messages.t("color.scheme.dialog.already.exists.error"), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    themeName = JOptionPane.showInputDialog(this, themeName);
                }
                ColorScheme.add(themeName);
                _comboBox.addItem(themeName);
                _comboBox.setSelectedItem(themeName);
            }
        }
    });
    buttons.add(button);
    add(buttons);
}

From source file:MainClass.java

public MainClass() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(350, 200);/*  w w  w .  j  a  v a 2  s . c o  m*/

    JTable table = new JTable(qtm);
    JScrollPane scrollpane = new JScrollPane(table);
    JPanel commandPanel = new JPanel();
    commandPanel.setLayout(new GridLayout(3, 2));
    commandPanel.add(new JLabel("Enter the Host URL: "));
    commandPanel.add(hostField = new JTextField());
    commandPanel.add(new JLabel("Enter your query: "));
    commandPanel.add(queryField = new JTextField());
    commandPanel.add(new JLabel("Click here to send: "));

    JButton jb = new JButton("Search");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            qtm.setHostURL(hostField.getText().trim());
            qtm.setQuery(queryField.getText().trim());
        }
    });
    commandPanel.add(jb);
    getContentPane().add(commandPanel, BorderLayout.NORTH);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
}

From source file:Main.java

public JComponent makeUI() {
    JPanel p = new JPanel(new GridLayout(2, 1));
    p.add(new JScrollPane(makeEditorPane(null)));
    p.add(new JScrollPane(makeEditorPane("bullet.png")));
    return p;//  w  ww .  ja v  a2s  .c  o m
}

From source file:Ellipse.java

public Ellipse() {
    super();//from   w w w.  ja  v  a  2 s.  c  o  m
    Container container = getContentPane();

    canvas = new DrawingCanvas();
    container.add(canvas);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));
    panel.add(new JLabel("x,y: ", JLabel.RIGHT));
    location = new JLabel("");
    panel.add(location);

    container.add(panel, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    setSize(600, 300);
    setVisible(true);
}

From source file:CommonLayouts.java

public CommonLayouts() {
    super("Common Layout Managers");
    setSize(500, 380);/*from   ww w.  ja v a 2s.  c  o  m*/

    JPanel desktop = new JPanel();
    getContentPane().add(desktop);

    JPanel fr1 = new JPanel();
    fr1.setBorder(new TitledBorder("FlowLayout"));
    fr1.setLayout(new FlowLayout());
    fr1.add(new JButton("1"));
    fr1.add(new JButton("2"));
    fr1.add(new JButton("3"));
    fr1.add(new JButton("4"));
    desktop.add(fr1, 0);

    JPanel fr2 = new JPanel();
    fr2.setBorder(new TitledBorder("GridLayout"));
    fr2.setLayout(new GridLayout(2, 2));
    fr2.add(new JButton("1"));
    fr2.add(new JButton("2"));
    fr2.add(new JButton("3"));
    fr2.add(new JButton("4"));
    desktop.add(fr2, 0);

    JPanel fr3 = new JPanel();
    fr3.setBorder(new TitledBorder("BorderLayout"));
    fr3.add(new JButton("1"), BorderLayout.NORTH);
    fr3.add(new JButton("2"), BorderLayout.EAST);
    fr3.add(new JButton("3"), BorderLayout.SOUTH);
    fr3.add(new JButton("4"), BorderLayout.WEST);
    desktop.add(fr3, 0);

    JPanel fr4 = new JPanel();
    fr4.setBorder(new TitledBorder("BoxLayout - X"));
    fr4.setLayout(new BoxLayout(fr4, BoxLayout.X_AXIS));
    fr4.add(new JButton("1"));
    fr4.add(Box.createHorizontalStrut(12));
    fr4.add(new JButton("2"));
    fr4.add(Box.createGlue());
    fr4.add(new JButton("3"));
    fr4.add(Box.createHorizontalGlue());
    fr4.add(new JButton("4"));
    desktop.add(fr4, 0);

    JPanel fr5 = new JPanel();
    fr5.setBorder(new TitledBorder("BoxLayout - Y"));
    fr5.setLayout(new BoxLayout(fr5, BoxLayout.Y_AXIS));
    fr5.add(new JButton("1"));
    fr5.add(Box.createVerticalStrut(10));
    fr5.add(new JButton("2"));
    fr5.add(Box.createGlue());
    fr5.add(new JButton("3"));
    fr5.add(Box.createVerticalGlue());
    fr5.add(new JButton("4"));
    desktop.add(fr5, 0);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}