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[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);

    // Create some data
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    model.removeRow(model.getRowCount() - 1);

    JFrame f = new JFrame();
    f.setSize(300, 300);//w w  w. ja  v a 2  s  .com
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Clipping.java

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

From source file:Main.java

public static void main(String argv[]) throws Exception {
    JComboBox<Item> comboBox = new JComboBox<Item>(
            new Item[] { new Item("Major", "red"), new Item("Critical", "dark"), new Item("Minor", "green") });
    comboBox.addActionListener(e -> {
        JComboBox<Item> combo = (JComboBox<Item>) e.getSource();
        Item item = (Item) combo.getSelectedItem();
        System.out.println(item.getColor());
    });//from w  w  w .j  a v a  2  s . c  o m
    JFrame frame = new JFrame();
    frame.add(comboBox);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    // Get all the table data
    Vector data = model.getDataVector();

    JFrame f = new JFrame();
    f.setSize(300, 300);//w  w w .ja v a  2 s  .c om
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    Vector rowData = new Vector();
    for (int i = 0; i < 1; i++) {
        Vector colData = new Vector(Arrays.asList("qq"));
        rowData.add(colData);// w  w  w .  ja va 2 s . c  om
    }

    String[] columnNames = { "a" };

    Vector columnNamesV = new Vector(Arrays.asList(columnNames));

    JTable table = new JTable(rowData, columnNamesV);
    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:BlurredImage.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Blurred Image");
    frame.add(new BlurredImage());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);//from   w  w w .j av a  2 s.com
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JComponent com = new DraggableComponent();

    JFrame f = new JFrame();

    f.add(com);
    f.setSize(300, 300);//ww w .j  a  v a 2  s .  c  o m
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);

    model.addColumn("Col1");
    model.addColumn("Col2");

    // Create the first row
    model.insertRow(0, new Object[] { "r1" });

    // Append a row
    model.insertRow(model.getRowCount(), new Object[] { "r5" });

    JFrame f = new JFrame();
    f.setSize(300, 300);//w w  w.  j  av  a 2 s. c  o m
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:RotatedText.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Rotated text");
    frame.add(new RotatedText());
    frame.setSize(400, 300);/* w ww. java  2  s  .co  m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);

    model.addColumn("Col1");
    model.addColumn("Col2");

    // Create the first row
    model.insertRow(0, new Object[] { "r1" });

    // Insert a row at position p
    int p = 1;/*from w ww .  j  ava  2 s .  c  o  m*/
    model.insertRow(p, new Object[] { "r3" });

    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}