Example usage for javax.swing JFrame add

List of usage examples for javax.swing JFrame add

Introduction

In this page you can find the example usage for javax.swing JFrame add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel(new BorderLayout());
    String[] values = new String[] { "One", "Two", "Three" };
    JComboBox<String> comboBox = new JComboBox<>(values);
    panel.add(comboBox, BorderLayout.NORTH);
    JTextArea textArea = new JTextArea(2, 2);
    panel.add(textArea, BorderLayout.CENTER);
    JButton button = new JButton("Action");
    button.addActionListener(new ActionListener() {
        @Override/*from w  ww .ja  v a 2  s  .co m*/
        public void actionPerformed(ActionEvent e) {
            textArea.setText((String) comboBox.getSelectedItem());
            comboBox.setSelectedIndex(0);
        }
    });
    panel.add(button, BorderLayout.SOUTH);
    JFrame frame = new JFrame();
    frame.add(panel);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Box box = Box.createVerticalBox();
    for (int i = 1; i < 4; i++) {
        JPanel panel = new JPanel() {
            @Override/*from w  w  w. jav a  2  s  .  c o m*/
            public Dimension getMaximumSize() {
                return getPreferredSize();
            }
        };
        JLabel label1 = new JLabel("Label");
        JLabel label2 = new JLabel(String.valueOf(i));
        panel.add(label1);
        panel.add(label2);
        box.add(panel);

    }

    JFrame frame = new JFrame();
    frame.add(box);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Composition");
    frame.add(new Main());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 120);//  w w  w  . j  a va  2s  . c o m
    frame.setVisible(true);
}

From source file:CompositingDST.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Composition");
    frame.add(new CompositingDST());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 120);/*from  ww w. jav a 2  s  . com*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    DefaultTableModel model;//from  www  . j a  va  2  s .c om
    JTable t = new JTable(model = new DefaultTableModel(0, 1));
    for (int i = 0; i < 10; i++) {
        model.addRow(new Object[] { i });
    }
    JButton removeSelected = new JButton("remove");
    removeSelected.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int[] selectedRows = t.getSelectedRows();
            for (int i = selectedRows.length - 1; i >= 0; i--) {
                model.removeRow(selectedRows[i]);
                ;
            }
        }
    });
    JFrame f = new JFrame();
    f.add(new JScrollPane(t));
    f.add(removeSelected, BorderLayout.SOUTH);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}

From source file:TextAttributesSuperscript.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Text attributes");
    frame.add(new TextAttributesSuperscript());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(620, 190);//from  www . j  a v  a2  s  .com
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:TextAttributesSize.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Text attributes");
    frame.add(new TextAttributesSize());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(620, 190);// ww  w  .  j ava2s  .c  o  m
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:TextAttributesBackground.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Text attributes");
    frame.add(new TextAttributesBackground());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(620, 190);/*from w  ww.ja  v a 2 s .  c o  m*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:TextAttributesStrikeThrough.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Text attributes");
    frame.add(new TextAttributesStrikeThrough());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(620, 190);//from   w w w .j a v  a2s . c o m
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:TextAttributesColor.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Text attributes");
    frame.add(new TextAttributesColor());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(620, 190);/*from   w w  w  . ja v  a2s  .  co  m*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}