List of usage examples for javax.swing JTable JTable
public JTable(final Object[][] rowData, final Object[] columnNames)
JTable
to display the values in the two dimensional array, rowData
, with column names, columnNames
. From source file:Main.java
public static void main(String args[]) { Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" }, { "Row2-Column1", "Row2-Column2", "Row2-Column3" } }; Object columnNames[] = { "Column 1", "Column 2", "Column 3" }; JTable table = new JTable(rowData, columnNames); table.setTableHeader(null);//from w w w . ja v a2 s .com JScrollPane scrollPane = new JScrollPane(table); scrollPane.setColumnHeaderView(null); JFrame frame = new JFrame(); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } }; final Object headers[] = { "English", "Digit" }; JFrame frame = new JFrame("Scrollless Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); JViewport viewport = new JViewport(); viewport.setView(table);/*from w w w.j a va2s . c o m*/ scrollPane.setColumnHeaderView(new JLabel("table header here")); scrollPane.setRowHeaderView(viewport); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:JScrollPaneHeadersandCorners.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, };//from www . j av a 2 s.c om final Object headers[] = { "English", "#" }; JFrame frame = new JFrame("Table Printing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new JButton("...")); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Table Title", TitledBorder.CENTER, TitledBorder.TOP)); JTable table = new JTable(3, 3); panel.add(new JScrollPane(table)); frame.add(panel);/*from w w w . j ava2s .co m*/ frame.pack(); frame.setVisible(true); }
From source file:HeaderlessSample.java
public static void main(String args[]) { Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" }, { "Row2-Column1", "Row2-Column2", "Row2-Column3" } }; Object columnNames[] = { "Column 1", "Column 2", "Column 3" }; // JTable table = new HeaderlessTable(rowData, columnNames); JTable table = new JTable(rowData, columnNames); table.setTableHeader(null);/*from w ww .j a v a2 s . c o m*/ JScrollPane scrollPane = new JScrollPane(table); // scrollPane.setColumnHeaderView(null); JFrame frame = new JFrame("Headerless Table"); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] headers = { "column 1", "column 2", "column 3", "column 4" }; int cols = 4; int rows = 6; String[][] data = new String[rows][cols]; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { data[row][col] = "item " + (row * cols + col + 1); }/*from w w w .j a v a2 s . c o m*/ } JTable table = new JTable(data, headers); DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) table.getDefaultRenderer(String.class); renderer.setHorizontalAlignment(JLabel.RIGHT); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(table)); f.setSize(400, 400); f.setLocation(200, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String[] columnNames = { "Date", "Field", "Home Team", "Visitor Team", "Score" }; JFrame guiFrame = new JFrame(); guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); guiFrame.setSize(500, 500);/*from ww w . j av a 2s.co m*/ JPanel panel = new JPanel(); panel.setSize(450, 450); JLabel titleLabel = new JLabel("OK"); String[][] data = new String[0][0]; JTable scheduleTable = new JTable(data, columnNames); JScrollPane scrollPane = new JScrollPane(scheduleTable); panel.add(scrollPane); panel.add(titleLabel); guiFrame.add(panel); guiFrame.setVisible(true); }
From source file:ScrollTableSample.java
public static void main(String args[]) { Object rows[][] = { { "one", "ichi - \u4E00" }, { "two", "ni - \u4E8C" }, { "three", "san - \u4E09" }, { "four", "shi - \u56DB" }, { "five", "go - \u4E94" }, { "six", "roku - \u516D" }, { "seven", "shichi - \u4E03" }, { "eight", "hachi - \u516B" }, { "nine", "kyu - \u4E5D" }, { "ten", "ju - \u5341" } }; Object headers[] = { "English", "Japanese" }; JFrame frame = new JFrame("Scrollless Table"); JTable table = new JTable(rows, headers); frame.getContentPane().add(table, BorderLayout.CENTER); frame.setSize(300, 150);//from w w w.j a v a 2 s .c o m frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } }; String headers[] = { "Upper", "Lower" }; JFrame frame = new JFrame("Tooltip Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); JLabel headerRenderer = new DefaultTableCellRenderer(); String columnName = table.getModel().getColumnName(0); headerRenderer.setText(columnName);/*from w w w.ja v a 2 s . c o m*/ headerRenderer.setToolTipText("Wave"); TableColumnModel columnModel = table.getColumnModel(); TableColumn column = columnModel.getColumn(0); column.setHeaderRenderer((TableCellRenderer) headerRenderer); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:LabelHeaderSample.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } }; JFrame frame = new JFrame("Label Header"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String headers[] = { "English", "#" }; JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); JLabel headerRenderer = new DefaultTableCellRenderer(); String columnName = table.getModel().getColumnName(0); headerRenderer.setText(columnName);//from w ww .j a v a2 s.c o m headerRenderer.setToolTipText("text"); TableColumnModel columnModel = table.getColumnModel(); TableColumn englishColumn = columnModel.getColumn(0); englishColumn.setHeaderRenderer((TableCellRenderer) headerRenderer); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }