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() 

Source Link

Document

Creates a grid layout with a default of one column per component, in a single row.

Usage

From source file:UserInterface.FarmerRole.ThermometerDemo.java

public ThermometerDemo(double value, String type) {
    this.setLayout(new GridLayout());
    DefaultValueDataset dataset = new DefaultValueDataset(value);
    if (type.equals("high")) {
        ThermometerPlot plot = new ThermometerPlot(dataset);
        plot.setSubrangePaint(0, Color.green.darker());
        plot.setSubrangePaint(1, Color.ORANGE);
        plot.setSubrangePaint(2, Color.RED.darker());

        plot.setSubrangeInfo(0, 10, 28, 30, 60);

        JFreeChart chart = new JFreeChart("Cold Storage", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        this.add(new ChartPanel(chart, W, H, W, H, W, H, false, true, true, true, true, true));
    } else if (type.equals("medium")) {
        ThermometerPlot plot = new ThermometerPlot(dataset);
        plot.setSubrangePaint(0, Color.green.darker());
        plot.setSubrangePaint(1, Color.ORANGE);
        plot.setSubrangePaint(2, Color.RED.darker());

        plot.setSubrangeInfo(0, 12, 14, 30, 60);

        JFreeChart chart = new JFreeChart("Medium Storage", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        this.add(new ChartPanel(chart, W, H, W, H, W, H, false, true, true, true, true, true));
    } else {/*from   w w  w .j a  va 2  s  .com*/
        ThermometerPlot plot = new ThermometerPlot(dataset);
        plot.setSubrangePaint(0, Color.green.darker());
        plot.setSubrangePaint(1, Color.YELLOW);
        plot.setSubrangePaint(2, Color.RED.darker());

        plot.setSubrangeInfo(0, 20, 35, 46, 60);

        JFreeChart chart = new JFreeChart("Warm Storage", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        this.add(new ChartPanel(chart, W, H, W, H, W, H, false, true, true, true, true, true));
    }
}

From source file:Main.java

public Main() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);// w w w .j av  a 2 s  .co  m
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    JScrollPane scroller = new JScrollPane(textArea);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(scroller, BorderLayout.CENTER);

    textArea.getDocument().addUndoableEditListener(new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
            updateButtons();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:UndoRedoTextArea.java

public UndoRedoTextArea() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);//from  ww w  .j  a v  a  2 s.  c om
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    JScrollPane scroller = new JScrollPane(textArea);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(scroller, BorderLayout.CENTER);

    textArea.getDocument().addUndoableEditListener(new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
            updateButtons();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:UndoManagerDemo.java

public UndoManagerDemo() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);//from   www . j  a v  a  2s .co m
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(canvas, BorderLayout.CENTER);

    canvas.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            Point point = new Point(e.getX(), e.getY());
            pointVector.addElement(point);

            undoManager.undoableEditHappened(
                    new UndoableEditEvent(canvas, new UndoablePaintSquare(point, pointVector)));

            undoButton.setText(undoManager.getUndoPresentationName());
            redoButton.setText(undoManager.getRedoPresentationName());
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
            canvas.repaint();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:Main.java

public Main() {
    Icon icon = UIManager.getIcon("html.pendingImage");
    JTabbedPane jtb = new JTabbedPane();

    JPanel jplInnerPanel1 = createInnerPanel("Tab 1: Tooltip and Icon");
    jtb.addTab("One", icon, jplInnerPanel1, "Tab 1");
    jtb.setSelectedIndex(0);/*from w w w  .j  a  v a  2 s  .  com*/

    JPanel jplInnerPanel2 = createInnerPanel("Tab 2: Icon only");
    jtb.addTab("Two", icon, jplInnerPanel2);

    JPanel jplInnerPanel3 = createInnerPanel("Tab 3: Tooltip and Icon");
    jtb.addTab("Three", icon, jplInnerPanel3, "Tab 3");

    JPanel jplInnerPanel4 = createInnerPanel("Tab 4: Text only");
    jtb.addTab("Four", jplInnerPanel4);

    menu.add(new JMenuItem("Item 1"));
    menu.add(new JMenuItem("Item 2"));

    JLabel tab4Label = new JLabel();
    tab4Label.setText("Four");
    jtb.setTabComponentAt(3, tab4Label);
    tab4Label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            maybeShowPopup(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            maybeShowPopup(e);
        }

        private void maybeShowPopup(MouseEvent e) {
            jtb.getModel().setSelectedIndex(3);
            if (e.isPopupTrigger()) {
                menu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });
    setLayout(new GridLayout());
    add(jtb);
}