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:AnotherBorderTest.java

public AnotherBorderTest() {
    setTitle("Border Test");
    setSize(450, 450);/* w  ww.j  a v a 2  s .c  o m*/

    JPanel content = (JPanel) getContentPane();
    content.setLayout(new GridLayout(6, 2, 3, 3));

    JPanel p = new JPanel();
    p.setBorder(new BevelBorder(BevelBorder.RAISED));
    p.add(new JLabel("RAISED BevelBorder"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new BevelBorder(BevelBorder.LOWERED));
    p.add(new JLabel("LOWERED BevelBorder"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new LineBorder(Color.black, 5));
    p.add(new JLabel("Black LineBorder, thickness = 5"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new EmptyBorder(10, 10, 10, 10));
    p.add(new JLabel("EmptyBorder with thickness of 10"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new EtchedBorder(EtchedBorder.RAISED));
    p.add(new JLabel("RAISED EtchedBorder"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
    p.add(new JLabel("LOWERED EtchedBorder"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
    p.add(new JLabel("RAISED SoftBevelBorder"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED));
    p.add(new JLabel("LOWERED SoftBevelBorder"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new MatteBorder(new ImageIcon("BALL.GIF")));
    p.add(new JLabel("MatteBorder"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new TitledBorder(new MatteBorder(new ImageIcon("java2sLogo.gif")), "Title String"));
    p.add(new JLabel("TitledBorder using MatteBorder"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new TitledBorder(new LineBorder(Color.black, 5), "Title String"));
    p.add(new JLabel("TitledBorder using LineBorder"));
    content.add(p);

    p = new JPanel();
    p.setBorder(new TitledBorder(new EmptyBorder(10, 10, 10, 10), "Title String"));
    p.add(new JLabel("TitledBorder using EmptyBorder"));
    content.add(p);

    setVisible(true);
}

From source file:BorderTest.java

public BorderTest() {
    JPanel p = new JPanel();
    Border[] border = new Border[] { BorderFactory.createEtchedBorder(),
            BorderFactory.createTitledBorder("Border types"), BorderFactory.createLoweredBevelBorder(),
            BorderFactory.createRaisedBevelBorder(), BorderFactory.createEtchedBorder(),
            BorderFactory.createLineBorder(Color.blue),
            BorderFactory.createMatteBorder(10, 10, 10, 10, Color.blue), BorderFactory.createEmptyBorder()

    };//from w  w  w .  j a  v  a2  s. co m
    p.setLayout(new GridLayout(border.length, 0, 3, 3));

    for (int i = 0; i < border.length; i++) {
        JPanel borderPanel = new JPanel();
        borderPanel.setBorder(border[i]);
        p.add(borderPanel);
    }
    getContentPane().add(p, "Center");
    setTitle("BorderTest");
    setSize(600, 400);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
}

From source file:Main.java

public Main() {
    JPanel borderLayoutPanel = new JPanel(new BorderLayout());
    borderLayoutPanel.setBorder(BorderFactory.createTitledBorder("BorderLayout Panel"));
    borderLayoutPanel.add(createGridPanel(), BorderLayout.CENTER);

    JPanel flowLayoutPanel = new JPanel(new FlowLayout());
    flowLayoutPanel.setBorder(BorderFactory.createTitledBorder("FlowLayout Panel"));
    flowLayoutPanel.add(createGridPanel());

    setBorder(BorderFactory.createEmptyBorder(GAP, GAP, GAP, GAP));
    setLayout(new GridLayout(1, 0, GAP, 0));
    add(borderLayoutPanel);/* w w w.  jav  a  2  s .c om*/
    add(flowLayoutPanel);
}

From source file:Main.java

public Main() {
    for (int i = 0; i < 100000; i++) {
        listSomeString.add("-");
        listSomeString.add("A");
        listSomeString.add("B");
        listSomeString.add("C");
        listSomeString.add("D");
    }/*  w  w  w.  ja va2  s. c  o  m*/

    someComboBox.setEditable(true);
    someComboBox.getEditor().getEditorComponent().setBackground(Color.YELLOW);
    ((JTextField) someComboBox.getEditor().getEditorComponent()).setBackground(Color.YELLOW);

    frame = new JFrame();
    frame.setLayout(new GridLayout(0, 1, 10, 10));
    frame.add(someComboBox);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocation(100, 100);
    frame.pack();
    frame.setVisible(true);
}

From source file:GridLayoutPane.java

public GridLayoutPane() {
    // Layout components into a grid three columns wide, with the number
    // of rows depending on the number of components. Leave 10 pixels
    // of horizontal and vertical space between components
    this.setLayout(new GridLayout(0, 3, 10, 10));
    // Add some components
    for (int i = 1; i <= 12; i++)
        this.add(new JButton("Button #" + i));
}

From source file:Main.java

public Main() {
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new GridLayout(3, 1, 0, 5));
    northPanel.add(label);/*from w  w w  .  jav  a2s . co m*/
    northPanel.add(button);
    northPanel.add(comboBox);
    add(northPanel, BorderLayout.NORTH);
    JPanel southPanel = new JPanel();

    ItemHandler handler = new ItemHandler();
    southPanel.setLayout(new GridLayout(1, radio.length));

    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < radio.length; i++) {
        radio[i] = new JRadioButton(strings[i]);
        radio[i].addItemListener(handler);
        group.add(radio[i]);
        southPanel.add(radio[i]);
    }

    add(southPanel, BorderLayout.SOUTH);

    setSize(300, 200);
    setVisible(true);
    radio[0].setSelected(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:ScrollBarColorSelect.java

public ScrollBarColorSelect() {
    setTitle("ColorSelect");
    setSize(300, 200);//from w w  w  . ja  va  2  s  . c o  m
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = getContentPane();

    JPanel p = new JPanel();
    p.setLayout(new GridLayout(3, 2, 3, 3));

    p.add(redLabel = new JLabel("Red 0"));
    p.add(red = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
    red.setBlockIncrement(16);
    red.addAdjustmentListener(this);

    p.add(greenLabel = new JLabel("Green 0"));
    p.add(green = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
    green.setBlockIncrement(16);
    green.addAdjustmentListener(this);

    p.add(blueLabel = new JLabel("Blue 0"));
    p.add(blue = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
    blue.setBlockIncrement(16);
    blue.addAdjustmentListener(this);

    contentPane.add(p, "South");

    colorPanel = new JPanel();
    colorPanel.setBackground(new Color(0, 0, 0));
    contentPane.add(colorPanel, "Center");
}

From source file:com.polivoto.vistas.Editor.java

/**
 * Ventana Editor - configura el color de las preguntas.
 *///from  w w w.j av  a2 s.c  o m
public Editor(JSONArray js) {
    initComponents();
    for (int i = 0; i < js.length(); i++) {
        try {
            JPanel panel = new JPanel(new GridLayout(0, 2, 10, 10));
            panel.setBackground(new Color(255, 255, 255));
            jTabbedPane.add(panel, "Pregunta " + (i + 1));
            JLabel lab1 = new JLabel(
                    "Pregunta " + (i + 1) + ": " + ((JSONObject) js.get(i)).getString("pregunta"), JLabel.LEFT);
            lab1.setFont(new Font("Roboto", 1, 18));
            lab1.setForeground(new Color(134, 36, 31));
            panel.add(lab1);
            panel.add(new JLabel(""));
            JSONArray jarr = ((JSONObject) js.get(i)).getJSONArray("opciones");
            for (int j = 0; j < jarr.length(); j++) {
                JLabel lab2 = new JLabel("Opcin " + (j + 1) + ": " + jarr.getString(j), JLabel.LEFT);
                JButton colBut = new JButton("Seleccionar color de la opcin");
                colBut.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        jFrame1.setVisible(true);
                    }
                });
                lab2.setFont(new Font("Roboto", 1, 15));
                lab2.setForeground(new Color(0, 0, 0));
                panel.add(lab2);
                panel.add(colBut);
            }

        } catch (JSONException ex) {
            Logger.getLogger(AnalistaLocal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:org.jfree.chart.demo.Bottom_panel.java

/**
 * Create the panel./*from  www.  jav a2s.  c  o  m*/
 */
public Bottom_panel(ArrayList<Graphic> Grafs, ArrayList<XYSeries> series, int x, int y, int width, int height) {

    graf = Grafs.get(8);
    serie = series;
    setBounds(x, y, width, height);
    setLayout(new GridLayout(0, 4, 2, 0));
    final JCheckBox chckbxNewCheckBox_5 = new JCheckBox("Graph 1");
    chckbxNewCheckBox_5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            XYSeries sr = serie.get(0);

            if (chckbxNewCheckBox_5.isSelected() == true) {

                graf.change_data(serie.get(0), true);
            } else {
                graf.change_data(serie.get(0), false);
            }
        }
    });
    chckbxNewCheckBox_5.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_5);

    final JCheckBox chckbxNewCheckBox_1 = new JCheckBox("Graph2");
    chckbxNewCheckBox_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            XYSeries sr = serie.get(1);

            if (chckbxNewCheckBox_1.isSelected() == true) {

                graf.change_data(serie.get(1), true);
            } else {
                graf.change_data(serie.get(1), false);
            }
        }

    });
    chckbxNewCheckBox_1.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_1);

    final JCheckBox chckbxNewCheckBox_2 = new JCheckBox("Graph 3");
    chckbxNewCheckBox_2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(2);

            if (chckbxNewCheckBox_2.isSelected() == true) {

                graf.change_data(serie.get(2), true);
            } else {
                graf.change_data(serie.get(2), false);
            }
        }

    });
    chckbxNewCheckBox_2.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_2);

    final JCheckBox chckbxNewCheckBox = new JCheckBox("Graph 4");
    chckbxNewCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(3);

            if (chckbxNewCheckBox.isSelected() == true) {

                graf.change_data(serie.get(3), true);
            } else {
                graf.change_data(serie.get(3), false);
            }
        }

    });
    chckbxNewCheckBox.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox);

    final JCheckBox chckbxNewCheckBox_3 = new JCheckBox("Graph 5");
    chckbxNewCheckBox_3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(4);

            if (chckbxNewCheckBox_3.isSelected() == true) {

                graf.change_data(serie.get(4), true);
            } else {
                graf.change_data(serie.get(4), false);
            }
        }

    });
    chckbxNewCheckBox_3.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_3);

    final JCheckBox chckbxNewCheckBox_4 = new JCheckBox("Graph 6");
    chckbxNewCheckBox_4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(5);

            if (chckbxNewCheckBox_4.isSelected() == true) {

                graf.change_data(serie.get(5), true);
            } else {
                graf.change_data(serie.get(5), false);
            }
        }
    });
    chckbxNewCheckBox_4.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_4);

    final JCheckBox chckbxNewCheckBox_6 = new JCheckBox("Graph 7");
    chckbxNewCheckBox_6.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(6);

            if (chckbxNewCheckBox_6.isSelected() == true) {

                graf.change_data(serie.get(6), true);
            } else {
                graf.change_data(serie.get(6), false);
            }
        }

    });
    chckbxNewCheckBox_6.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_6);

    final JCheckBox chckbxNewCheckBox_7 = new JCheckBox("Graph 8");
    chckbxNewCheckBox_7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(7);

            if (chckbxNewCheckBox_6.isSelected() == true) {

                graf.change_data(serie.get(7), true);
            } else {
                graf.change_data(serie.get(7), false);
            }
        }

    });
    chckbxNewCheckBox_7.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_7);

}

From source file:ScrollDemo.java

public void init() {
    JRadioButton form[][] = new JRadioButton[12][5];
    String counts[] = { "", "0-1", "2-5", "6-10", "11-100", "101+" };
    String categories[] = { "Household", "Office", "Extended Family", "Company (US)", "Company (World)", "Team",
            "Will", "Birthday Card List", "High School", "Country", "Continent", "Planet" };
    JPanel p = new JPanel();
    p.setSize(600, 400);/*from  w  ww.jav a 2s.c  o  m*/
    p.setLayout(new GridLayout(13, 6, 10, 0));
    for (int row = 0; row < 13; row++) {
        ButtonGroup bg = new ButtonGroup();
        for (int col = 0; col < 6; col++) {
            if (row == 0) {
                p.add(new JLabel(counts[col]));
            } else {
                if (col == 0) {
                    p.add(new JLabel(categories[row - 1]));
                } else {
                    form[row - 1][col - 1] = new JRadioButton();
                    bg.add(form[row - 1][col - 1]);
                    p.add(form[row - 1][col - 1]);
                }
            }
        }
    }
    scrollpane = new JScrollPane(p);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
}