Example usage for javax.swing JTable JTable

List of usage examples for javax.swing JTable JTable

Introduction

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

Prototype

public JTable(TableModel dm) 

Source Link

Document

Constructs a JTable that is initialized with dm as the data model, a default column model, and a default selection model.

Usage

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");

    table.getColumnModel().getColumn(0).setHeaderValue("New Name");
    table.getTableHeader().resizeAndRepaint();

}

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");

}

From source file:Main.java

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

    // Disable autoCreateColumnsFromModel
    table.setAutoCreateColumnsFromModel(false);

}

From source file:Main.java

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

    // Add a column with values.
    model.addColumn("Col2", new Object[] { "v2" });

}

From source file:Main.java

public static void main(String[] argv) {
    DefaultTableModel model = new DefaultTableModel();
    JTable table1 = new JTable(model);
    JTable table2 = new JTable(model);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.add(new JScrollPane(table1));
    splitPane.add(new JScrollPane(table2));

    table1.getColumnModel().removeColumn(table1.getColumnModel().getColumn(0));
}

From source file:Main.java

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

    model = (DefaultTableModel) table.getModel();
    TableColumn col = new TableColumn(model.getColumnCount());

    // Ensure that auto-create is off
    if (table.getAutoCreateColumnsFromModel()) {
        throw new IllegalStateException();
    }/*from  ww  w  .  j a  v  a 2s .co  m*/
    col.setHeaderValue("Col3");
    table.addColumn(col);
    model.addColumn("Col3", new Object[] { "v3" });

}

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");

    JFrame f = new JFrame();
    f.setSize(300, 300);//w  w w.j a  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) 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" });

    JFrame f = new JFrame();
    f.setSize(300, 300);/*from ww  w. ja  va 2 s  .  co  m*/
    f.add(new JScrollPane(table));
    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.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    // Remove the first row
    model.removeRow(0);/*from   w  ww  . j  ava  2 s  .c o m*/

    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    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.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    // Move the last row to the beginning of the table
    model.moveRow(model.getRowCount() - 1, model.getRowCount() - 1, 0);

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