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

public static void main(String[] args) {
    JFrame frame = new JFrame("Borders");

    int center = SwingConstants.CENTER;
    JLabel labelOne = new JLabel("raised BevelBorder", center);
    labelOne.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    JLabel labelTwo = new JLabel("EtchedBorder", center);
    labelTwo.setBorder(BorderFactory.createEtchedBorder());
    JLabel labelThree = new JLabel("MatteBorder", center);
    labelThree.setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.pink));
    JLabel labelFour = new JLabel("TitledBorder", center);
    Border etch = BorderFactory.createEtchedBorder();
    labelFour.setBorder(BorderFactory.createTitledBorder(etch, "Title"));
    JLabel labelFive = new JLabel("TitledBorder", center);
    Border low = BorderFactory.createLoweredBevelBorder();
    labelFive//  w  w w.j a  v  a2s. c  om
            .setBorder(BorderFactory.createTitledBorder(low, "Title", TitledBorder.RIGHT, TitledBorder.BOTTOM));
    JLabel labelSix = new JLabel("CompoundBorder", center);
    Border one = BorderFactory.createEtchedBorder();
    Border two = BorderFactory.createMatteBorder(4, 4, 4, 4, Color.blue);
    labelSix.setBorder(BorderFactory.createCompoundBorder(one, two));

    frame.setLayout(new GridLayout(3, 2));
    frame.add(labelOne);
    frame.add(labelTwo);
    frame.add(labelThree);
    frame.add(labelFour);
    frame.add(labelFive);
    frame.add(labelSix);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:net.redstonelamp.gui.RedstoneLampGUI.java

public static void main(String[] args) {
    JFrame frame = new JFrame("RedstoneLamp");
    frame.setLayout(new GridLayout(2, 1));
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    JLabel label = new JLabel("RedstoneLamp");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    frame.add(label);/*from  ww  w  .  j a v  a  2s  .c o  m*/
    JPanel lowPanel = new JPanel();
    JPanel left = new JPanel();
    left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
    lowPanel.add(left);
    JPanel right = new JPanel();
    right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));
    lowPanel.add(right);
    JButton openButton = new JButton("Open server at...");
    openButton.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(new File("."));
        chooser.setDialogTitle("Select RedstoneLamp server home");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        int action = chooser.showOpenDialog(frame);
        if (action == JFileChooser.APPROVE_OPTION) {
            File selected = chooser.getSelectedFile();
            File jar = new File("RedstoneLamp.jar");
            if (!jar.isFile()) {
                int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. "
                        + "Would you like to install RedstoneLamp there?");
                if (result == JOptionPane.YES_OPTION) {
                    installCallback(frame, selected);
                }
                return;
            }
            frame.dispose();
            addHistory(selected);
            currentRoot = new ServerActivity(selected);
        }
    });
    right.add(openButton);
    JButton installButton = new JButton("Install server at...");
    installButton.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(".");
        chooser.setDialogTitle("Select directory to install server in");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        int action = chooser.showSaveDialog(frame);
        if (action == JFileChooser.APPROVE_OPTION) {
            File selected = chooser.getSelectedFile();
            File jar = new File("RedstoneLamp.jar");
            if (jar.isFile()) {
                int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. "
                        + "Are you sure you want to reinstall RedstoneLamp there?");
                if (result == JOptionPane.NO_OPTION) {
                    frame.dispose();
                    addHistory(selected);
                    currentRoot = new ServerActivity(selected);
                    return;
                }
            }
            installCallback(frame, selected);
        }
    });
    frame.add(lowPanel);
    frame.pack();
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(dimension.width / 2 - frame.getSize().width / 2,
            dimension.height / 2 - frame.getSize().height / 2);
    frame.setVisible(true);
}

From source file:ACompoundBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Compound Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border lineBorder = LineBorder.createBlackLineBorder();
    Border bevelBorder = BorderFactory.createRaisedBevelBorder();
    Border bevelLineBorder = new CompoundBorder(bevelBorder, lineBorder);
    JButton bevelLineButton = new JButton("Bevel Line");
    bevelLineButton.setBorder(bevelLineBorder);
    Border redBorder = BorderFactory.createLineBorder(Color.MAGENTA, 2);
    Border orangeBorder = BorderFactory.createLineBorder(Color.BLUE, 2);
    Border yellowBorder = BorderFactory.createLineBorder(Color.YELLOW, 5);
    Border greenBorder = BorderFactory.createLineBorder(Color.GREEN, 2);
    Border blueBorder = BorderFactory.createLineBorder(Color.ORANGE, 4);
    Border magentaBorder = BorderFactory.createLineBorder(Color.RED, 3);
    Border twoColorBorder = new CompoundBorder(magentaBorder, blueBorder);
    Border threeColorBorder = new CompoundBorder(twoColorBorder, greenBorder);
    Border fourColorBorder = new CompoundBorder(threeColorBorder, yellowBorder);
    Border fiveColorBorder = new CompoundBorder(fourColorBorder, orangeBorder);
    Border sixColorBorder = new CompoundBorder(fiveColorBorder, redBorder);
    JButton rainbowButton = new JButton("Rainbow");
    rainbowButton.setBorder(sixColorBorder);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(1, 2));
    contentPane.add(bevelLineButton);//from www  .j av a2  s .  c  o  m
    contentPane.add(rainbowButton);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:TitledPostBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Positioned Titled Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    TitledBorder aboveTopBorder = BorderFactory.createTitledBorder("AboveTop");
    aboveTopBorder.setTitlePosition(TitledBorder.ABOVE_TOP);
    JButton aboveTopButton = new JButton();
    aboveTopButton.setBorder(aboveTopBorder);
    TitledBorder topBorder = BorderFactory.createTitledBorder("Top");
    topBorder.setTitlePosition(TitledBorder.TOP);
    JButton topButton = new JButton();
    topButton.setBorder(topBorder);//from   w w w  .j  a v a2  s .  co m
    TitledBorder belowTopBorder = BorderFactory.createTitledBorder("BelowTop");
    belowTopBorder.setTitlePosition(TitledBorder.BELOW_TOP);
    JButton belowTopButton = new JButton();
    belowTopButton.setBorder(belowTopBorder);
    TitledBorder aboveBottomBorder = BorderFactory.createTitledBorder("AboveBottom");
    aboveBottomBorder.setTitlePosition(TitledBorder.ABOVE_BOTTOM);
    JButton aboveBottomButton = new JButton();
    aboveBottomButton.setBorder(aboveBottomBorder);
    TitledBorder bottomBorder = BorderFactory.createTitledBorder("Bottom");
    bottomBorder.setTitlePosition(TitledBorder.BOTTOM);
    JButton bottomButton = new JButton();
    bottomButton.setBorder(bottomBorder);
    TitledBorder belowBottomBorder = BorderFactory.createTitledBorder("BelowBottom");
    belowBottomBorder.setTitlePosition(TitledBorder.BELOW_BOTTOM);
    JButton belowBottomButton = new JButton();
    belowBottomButton.setBorder(belowBottomBorder);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(3, 2));
    contentPane.add(aboveTopButton);
    contentPane.add(aboveBottomButton);
    contentPane.add(topButton);
    contentPane.add(bottomButton);
    contentPane.add(belowTopButton);
    contentPane.add(belowBottomButton);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:TitledPostBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Positioned Titled Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    TitledBorder aboveTopBorder = BorderFactory.createTitledBorder("AboveTop");
    aboveTopBorder.setTitlePosition(TitledBorder.ABOVE_TOP);
    JButton aboveTopButton = new JButton();
    aboveTopButton.setBorder(aboveTopBorder);

    TitledBorder topBorder = BorderFactory.createTitledBorder("Top");
    topBorder.setTitlePosition(TitledBorder.TOP);
    JButton topButton = new JButton();
    topButton.setBorder(topBorder);//ww  w  .j av  a2  s.  co  m

    TitledBorder belowTopBorder = BorderFactory.createTitledBorder("BelowTop");
    belowTopBorder.setTitlePosition(TitledBorder.BELOW_TOP);
    JButton belowTopButton = new JButton();
    belowTopButton.setBorder(belowTopBorder);

    TitledBorder aboveBottomBorder = BorderFactory.createTitledBorder("AboveBottom");
    aboveBottomBorder.setTitlePosition(TitledBorder.ABOVE_BOTTOM);
    JButton aboveBottomButton = new JButton();
    aboveBottomButton.setBorder(aboveBottomBorder);

    TitledBorder bottomBorder = BorderFactory.createTitledBorder("Bottom");
    bottomBorder.setTitlePosition(TitledBorder.BOTTOM);
    JButton bottomButton = new JButton();
    bottomButton.setBorder(bottomBorder);

    TitledBorder belowBottomBorder = BorderFactory.createTitledBorder("BelowBottom");
    belowBottomBorder.setTitlePosition(TitledBorder.BELOW_BOTTOM);
    JButton belowBottomButton = new JButton();
    belowBottomButton.setBorder(belowBottomBorder);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(3, 2));
    contentPane.add(aboveTopButton);
    contentPane.add(aboveBottomButton);
    contentPane.add(topButton);
    contentPane.add(bottomButton);
    contentPane.add(belowTopButton);
    contentPane.add(belowBottomButton);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:com.joey.software.dsp.HilbertTransform.java

public static void main(String input[]) {
    int length = 5000;

    float[] reInput = FFTSpeedTest.getSinData(length, 1000);
    float[] imInput = FFTSpeedTest.getStaticData(length, 0f);

    float[] reOutput = new float[length];
    float[] imOutput = new float[length];

    FastFourierTransform3 fft = new FastFourierTransform3(length);
    fft.fft(reInput, imInput, reOutput, imOutput);

    HilbertTransform ht = new HilbertTransform();
    getHilbert(reInput, imInput, reOutput, imOutput);

    JFreeChart inputPlot = PlotingToolkit.getPlot(new float[][] { reInput, imInput },
            new String[] { "Real", "Imaginary" }, "Input Data", "X Data", "Y Data");

    JFreeChart outputPlot = PlotingToolkit.getPlot(new float[][] { reOutput, imOutput },
            new String[] { "Real", "Imaginary" }, "Output Data", "X Data", "Y Data");

    ChartPanel p1 = new ChartPanel(inputPlot);
    ChartPanel p2 = new ChartPanel(outputPlot);

    JPanel p = new JPanel(new GridLayout(1, 2));
    p.add(p1);/*w  w w .  j a v  a2  s .c  om*/
    p.add(p2);

    FrameFactroy.getFrame(p);
}

From source file:Main.java

public static void main(String[] args) {
    JRadioButton dem = new JRadioButton("Bill", false);
    dem.setActionCommand("Bill");
    JRadioButton rep = new JRadioButton("Bob", false);
    rep.setActionCommand("Bob");
    JRadioButton ind = new JRadioButton("Ross", false);
    ind.setActionCommand("Ross");

    final ButtonGroup group = new ButtonGroup();
    group.add(dem);/*from  w w w  . ja  v  a2  s.  co  m*/
    group.add(rep);
    group.add(ind);

    class VoteActionListener implements ActionListener {
        public void actionPerformed(ActionEvent ex) {
            String choice = group.getSelection().getActionCommand();
            System.out.println("ACTION Candidate Selected: " + choice);
        }
    }

    class VoteItemListener implements ItemListener {
        public void itemStateChanged(ItemEvent ex) {
            String item = ((AbstractButton) ex.getItemSelectable()).getActionCommand();
            boolean selected = (ex.getStateChange() == ItemEvent.SELECTED);
            System.out.println("ITEM Candidate Selected: " + selected + " Selection: " + item);
        }
    }

    ActionListener al = new VoteActionListener();
    dem.addActionListener(al);
    rep.addActionListener(al);
    ind.addActionListener(al);

    ItemListener il = new VoteItemListener();
    dem.addItemListener(il);
    rep.addItemListener(il);
    ind.addItemListener(il);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c = frame.getContentPane();
    c.setLayout(new GridLayout(4, 1));
    c.add(new JLabel("Please Cast Your Vote"));
    c.add(dem);
    c.add(rep);
    c.add(ind);
    frame.pack();
    frame.setVisible(true);
}

From source file:IconCheckBoxSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Iconizing CheckBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon checked = new DiamondIcon(Color.black, true);
    Icon unchecked = new DiamondIcon(Color.black, false);
    JCheckBox aCheckBox1 = new JCheckBox("Pizza", unchecked);
    aCheckBox1.setSelectedIcon(checked);
    JCheckBox aCheckBox2 = new JCheckBox("Calzone");
    aCheckBox2.setIcon(unchecked);//  ww  w  .j a v a2  s . c o  m
    aCheckBox2.setSelectedIcon(checked);
    Icon checkBoxIcon = new CheckBoxIcon();
    JCheckBox aCheckBox3 = new JCheckBox("Anchovies", checkBoxIcon);
    JCheckBox aCheckBox4 = new JCheckBox("Stuffed Crust", checked);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(0, 1));
    contentPane.add(aCheckBox1);
    contentPane.add(aCheckBox2);
    contentPane.add(aCheckBox3);
    contentPane.add(aCheckBox4);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    String ACTION_KEY = "The Action";

    JFrame frame = new JFrame("KeyStroke Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton buttonA = new JButton("FOCUSED (control alt 7)");
    JButton buttonB = new JButton("FOCUS/RELEASE (VK_ENTER)");
    JButton buttonC = new JButton("ANCESTOR  (VK_F4+SHIFT_MASK)");
    JButton buttonD = new JButton("WINDOW (' ')");

    Action actionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent actionEvent) {
            JButton source = (JButton) actionEvent.getSource();
            System.out.println("Activated: " + source.getText());
        }//w  w  w  . j a v a2  s . com
    };

    KeyStroke controlAlt7 = KeyStroke.getKeyStroke("control alt 7");
    InputMap inputMap = buttonA.getInputMap();
    inputMap.put(controlAlt7, ACTION_KEY);
    ActionMap actionMap = buttonA.getActionMap();
    actionMap.put(ACTION_KEY, actionListener);

    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true);
    inputMap = buttonB.getInputMap();
    inputMap.put(enter, ACTION_KEY);
    buttonB.setActionMap(actionMap);

    KeyStroke shiftF4 = KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.SHIFT_MASK);
    inputMap = buttonC.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(shiftF4, ACTION_KEY);
    buttonC.setActionMap(actionMap);

    KeyStroke space = KeyStroke.getKeyStroke(' ');
    inputMap = buttonD.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(space, ACTION_KEY);
    buttonD.setActionMap(actionMap);

    frame.setLayout(new GridLayout(2, 2));
    frame.add(buttonA);
    frame.add(buttonB);
    frame.add(buttonC);
    frame.add(buttonD);

    frame.setSize(400, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    String ACTION_KEY = "The Action";

    JFrame frame = new JFrame("KeyStroke Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton buttonA = new JButton("FOCUSED (control alt 7)");
    JButton buttonB = new JButton("FOCUS/RELEASE (VK_ENTER)");
    JButton buttonC = new JButton("ANCESTOR  (VK_F4+SHIFT_MASK)");
    JButton buttonD = new JButton("WINDOW (' ')");

    Action actionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent actionEvent) {
            JButton source = (JButton) actionEvent.getSource();
            System.out.println("Activated: " + source.getText());
        }/*from   w  ww  .  j av  a2 s .  c  o m*/
    };

    KeyStroke controlAlt7 = KeyStroke.getKeyStroke("control alt 7");
    InputMap inputMap = buttonA.getInputMap();
    inputMap.put(controlAlt7, ACTION_KEY);
    ActionMap actionMap = buttonA.getActionMap();
    actionMap.clear();
    actionMap.put(ACTION_KEY, actionListener);

    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true);
    inputMap = buttonB.getInputMap();
    inputMap.put(enter, ACTION_KEY);
    buttonB.setActionMap(actionMap);

    KeyStroke shiftF4 = KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.SHIFT_MASK);
    inputMap = buttonC.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(shiftF4, ACTION_KEY);
    buttonC.setActionMap(actionMap);

    KeyStroke space = KeyStroke.getKeyStroke(' ');
    inputMap = buttonD.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(space, ACTION_KEY);
    buttonD.setActionMap(actionMap);

    frame.setLayout(new GridLayout(2, 2));
    frame.add(buttonA);
    frame.add(buttonB);
    frame.add(buttonC);
    frame.add(buttonD);

    frame.setSize(400, 200);
    frame.setVisible(true);
}