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(final Object[][] rowData, final Object[] columnNames) 

Source Link

Document

Constructs a JTable to display the values in the two dimensional array, rowData, with column names, columnNames.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);/*from   w  w w. j a  v a  2  s. c  om*/

    int row = 5;
    int col = 3;
    boolean toggle = false;
    boolean extend = true;
    table.changeSelection(row, col, toggle, extend);

}

From source file:Main.java

public static void main(String args[]) {
    JTable table = new JTable(22, 5);
    table.setPreferredScrollableViewportSize(new Dimension(400, 300));
    final JScrollPane scrollPane = new JScrollPane(table);
    JButton cornerButton = new JButton("#");
    scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER, cornerButton);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    JFrame frame = new JFrame();
    frame.add(scrollPane);/*from   www . j ava2  s  .  c om*/
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object[][] cellData = { { "1-1", "1-2" }, { "2-1", "2-2" } };
    String[] columnNames = { "col1", "col2" };

    JTable table = new JTable(cellData, columnNames);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object[][] cellData = { { "1-1", "1-2" }, { "2-1", "2-2" } };
    String[] columnNames = { "col1", "col2" };

    JTable table = new JTable(cellData, columnNames);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object[][] cellData = { { "1-1", "1-2" }, { "2-1", "2-2" } };
    String[] columnNames = { "col1", "col2" };

    JTable table = new JTable(cellData, columnNames);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object[][] cellData = { { "1-1", "1-2" }, { "2-1", "2-2" } };
    String[] columnNames = { "col1", "col2" };

    JTable table = new JTable(cellData, columnNames);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object[][] cellData = { { "1-1", "1-2" }, { "2-1", "2-2" } };
    String[] columnNames = { "col1", "col2" };

    JTable table = new JTable(cellData, columnNames);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object[][] cellData = { { "1-1", "1-2" }, { "2-1", "2-2" } };
    String[] columnNames = { "col1", "col2" };

    JTable table = new JTable(cellData, columnNames);

    int rows = table.getRowCount();
    int cols = table.getColumnCount();

    System.out.println(rows);//  w  ww.j  ava  2  s.c  o  m
    System.out.println(cols);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame("Test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(new String[][] { { "One" }, { "Two" }, { "Three" } }, new String[] { "Ordinal" });
    table.addRowSelectionInterval(1, 1);
    f.add(new JScrollPane(table));
    f.pack();/*from ww w  .j av a2 s. c o m*/
    f.setLocationRelativeTo(null);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] argv) {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);
    JFrame f = new JFrame();
    f.setSize(300, 300);//from   ww  w .  j a  v a2 s.c om
    f.add(new JScrollPane(table));
    f.setVisible(true);

}