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

public Main() {
    super(new BorderLayout());
    amountDisplayFormat = NumberFormat.getCurrencyInstance();
    System.out.println(amountDisplayFormat.format(1200));
    amountDisplayFormat.setMinimumFractionDigits(0);
    amountEditFormat = NumberFormat.getNumberInstance();
    amountField = new JFormattedTextField(new DefaultFormatterFactory(new NumberFormatter(amountDisplayFormat),
            new NumberFormatter(amountDisplayFormat), new NumberFormatter(amountEditFormat)));
    amountField.setValue(new Double(amount));
    amountField.setColumns(10);/*from   w w  w.j a v  a2  s.  c  o m*/
    amountField.addPropertyChangeListener("value", this);

    JPanel fieldPane = new JPanel(new GridLayout(0, 1));
    fieldPane.add(amountField);

    add(fieldPane, BorderLayout.LINE_END);
    add(new JButton("Hello"), BorderLayout.SOUTH);
}

From source file:ColorApp.java

public ColorApp() {
    super();//  ww w. j  a  v a2 s . c  om
    Container container = getContentPane();

    displayPanel = new DisplayPanel();
    container.add(displayPanel);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(3, 2));
    panel.setBorder(new TitledBorder("Click a Button to Perform the Associated Operation and Reset..."));

    brightenButton = new JButton("Brightness >>");
    brightenButton.addActionListener(new ButtonListener());
    darkenButton = new JButton("Darkness >>");
    darkenButton.addActionListener(new ButtonListener());
    contrastIncButton = new JButton("Contrast >>");
    contrastIncButton.addActionListener(new ButtonListener());
    contrastDecButton = new JButton("Contrast <<");
    contrastDecButton.addActionListener(new ButtonListener());
    reverseButton = new JButton("Negative");
    reverseButton.addActionListener(new ButtonListener());
    resetButton = new JButton("Reset");
    resetButton.addActionListener(new ButtonListener());

    panel.add(brightenButton);
    panel.add(darkenButton);
    panel.add(contrastIncButton);
    panel.add(contrastDecButton);
    panel.add(reverseButton);
    panel.add(resetButton);

    container.add(BorderLayout.SOUTH, panel);

    addWindowListener(new WindowEventHandler());
    setSize(displayPanel.getWidth(), displayPanel.getHeight() + 25);
    show();
}

From source file:QandE.Layout2.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread./*  www . ja  v a2s  .c o m*/
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("Layout2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Add the innards.
    JPanel p = new JPanel(new GridLayout(1, 0));
    p.add(createComponent("Component 1"));
    p.add(createComponent("Component 2"));
    p.add(createComponent("Component 3"));
    p.add(createComponent("Component 4"));
    //p.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    frame.setContentPane(p);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Puts an array of components into a new panel with a label.
 * // w ww. j a  v a  2s . c om
 * @param a
 *            The Components to add.
 * @param label
 *            The label of the panel.
 * @return A Panel with the given label and the components inside.
 */
public static JPanel addToLabeledPanel(Component[] a, String label) {
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, a.length));
    addAll(a, panel);
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), label));
    return panel;
}

From source file:Main.java

public Main() {
    setLayout(new GridLayout(ROWS, COLS));
    for (int row = 0; row < grid.length; row++) {
        for (int col = 0; col < grid[row].length; col++) {
            JLabel label = new JLabel();
            int index = random.nextInt(COLORS.length);
            label.setIcon(ICONS[index]);
            add(label);/*from ww  w. j a  va  2s . c  o m*/
            grid[row][col] = label;
        }
    }
    new Timer(TIMER_DELAY, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            for (int i = 0; i < NUMBER_TO_SWAP; i++) {
                int row = random.nextInt(ROWS);
                int col = random.nextInt(COLS);
                int iconIndex = random.nextInt(ICONS.length);
                grid[row][col].setIcon(ICONS[iconIndex]);
            }
        }
    }).start();
}

From source file:DatabaseTest.java

public DatabaseTest() {
    super("Database Test Frame");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(350, 200);//from w  ww.  j a v a 2s. c o m

    qtm = new QueryTableModel();
    JTable table = new JTable(qtm);
    JScrollPane scrollpane = new JScrollPane(table);
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(3, 2));
    p1.add(new JLabel("Enter the Host URL: "));
    p1.add(hostField = new JTextField());
    p1.add(new JLabel("Enter your query: "));
    p1.add(queryField = new JTextField());
    p1.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());
        }
    });
    p1.add(jb);
    getContentPane().add(p1, BorderLayout.NORTH);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
}

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

public static JPanel createDemoPanel() {
    JPanel jpanel = new JPanel(new GridLayout(1, 3));
    DefaultValueDataset defaultvaluedataset = new DefaultValueDataset(23D);
    ChartPanel chartpanel = new ChartPanel(createChart("DialShape.PIE", defaultvaluedataset, DialShape.PIE));
    ChartPanel chartpanel1 = new ChartPanel(
            createChart("DialShape.CHORD", defaultvaluedataset, DialShape.CHORD));
    ChartPanel chartpanel2 = new ChartPanel(
            createChart("DialShape.CIRCLE", defaultvaluedataset, DialShape.CIRCLE));
    jpanel.add(chartpanel);//from   w w w  .  j  a v  a2 s . c om
    jpanel.add(chartpanel1);
    jpanel.add(chartpanel2);
    return jpanel;
}

From source file:compecon.dashboard.panel.MoneyPanel.java

public MoneyPanel() {
    this.setLayout(new GridLayout(0, 2));

    this.add(createKeyInterestRatesPanel());
    this.add(createPriceIndicesPanel());
    this.add(createMoneySupplyPanel());
    this.add(createMoneyCirculationPanel());
    this.add(createMoneyVelocityPanel());
    this.add(createCreditUtilizationRatePanel());
}

From source file:Main.java

public Main() {
    for (int i = 0; i < panels.length; i++) {
        final String[] labels = new String[] { "0", "1" };
        final Random rand = new Random();
        int index = rand.nextInt(labels.length);
        String randomTitle = labels[index];
        final JLabel label = new JLabel(randomTitle, JLabel.CENTER);
        Timer lblt = new Timer(00, new ActionListener() {
            @Override//from  w  w  w .  ja v a2 s .  co  m
            public void actionPerformed(ActionEvent ae) {
                label.setText(labels[rand.nextInt(labels.length)]);
            }
        });
        lblt.setRepeats(true);
        lblt.start();
        label.setForeground(Color.green);
        label.setVerticalAlignment(JLabel.CENTER);
        panels[i] = new JPanel();
        panels[i].setBackground(Color.BLACK);
        panels[i].add(label);
        frame.getContentPane().add(panels[i]);
    }
    frame.setLayout(new GridLayout(grid, grid));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
    frame.setVisible(true);

    ActionListener action = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < panels.length; i++) {
                Color mix = new Color(255, 255, 255);
                Random random = new Random();
                int r = random.nextInt(255);
                int g = random.nextInt(255);
                int b = random.nextInt(255);

                if (mix != null) {
                    r = (r + mix.getRed()) / 2;
                    g = (g + mix.getGreen()) / 2;
                    b = (b + mix.getBlue()) / 2;
                }
                Color color = new Color(r, g, b);
                panels[i].setBackground(color);
            }
        }
    };

    t = new Timer(00, action);
    t.setRepeats(true);
    t.start();
}

From source file:lu.lippmann.cdb.common.gui.MultiPanel.java

/**
 * Constructor.//  www.ja  va 2s.  c  o m
 */
public MultiPanel(final ListOrderedMap<JComponent, Integer> mapPanels, final int w, final int h,
        final boolean withWeight) {

    final int total = mapPanels.keySet().size();

    if (!withWeight)
        setLayout(new GridLayout(0, 1));

    final int w2 = w - 10 * total;
    final int h2 = h - 75;

    final Map<JComponent, Color> choosedColor = new HashMap<JComponent, Color>();

    int i = 0;
    for (final JComponent p : mapPanels.keySet()) {
        final Dimension size = new Dimension((int) (w2 * (mapPanels.get(p) / 100.0)), h2);
        p.setPreferredSize(size);
        choosedColor.put(p, COLORS[i]);
        p.setBackground(COLORS[i]);
        p.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        add(p);
        i++;
    }

    if (withWeight) {
        /** add percents **/
        for (final JComponent p : mapPanels.keySet()) {
            final int perc = mapPanels.get(p);
            final int percent = (int) (w2 * (mapPanels.get(p) / 100.0));
            final Dimension size = new Dimension(percent, 20);
            final JPanel arrow = new JPanel();
            arrow.setPreferredSize(size);
            final JLabel label = new JLabel(perc + "%");
            label.setForeground(choosedColor.get(p).darker());
            arrow.add(label);
            add(arrow);
        }
    }
}