List of usage examples for javax.swing JTable getColumn
public TableColumn getColumn(Object identifier)
TableColumn
object for the column in the table whose identifier is equal to identifier
, when compared using equals
. From source file:ChooserTableSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Editable Color Table"); TableModel model = new ColorTableModel(); JTable table = new JTable(model); TableColumn column = table.getColumnModel().getColumn(3); ComboTableCellRenderer renderer = new ComboTableCellRenderer(); column.setCellRenderer(renderer);/*from w w w .ja va2 s. c o m*/ TableCellEditor editor = new ColorChooserEditor(); column.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(table); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
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); JTableHeader header = table.getTableHeader(); ColumnHeaderToolTips tips = new ColumnHeaderToolTips(); for (int c = 0; c < table.getColumnCount(); c++) { TableColumn col = table.getColumnModel().getColumn(c); tips.setToolTip(col, "Col " + c); }/*from w ww . ja v a 2s . c o m*/ header.addMouseMotionListener(tips); }
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 { JTable table = new JTable(); DefaultTableModel model = (DefaultTableModel) table.getModel(); model.addColumn("A", new Object[] { "item1" }); model.addColumn("B", new Object[] { "item2" }); String[] values = new String[] { "1", "2", "3" }; TableColumn col = table.getColumnModel().getColumn(0); col.setCellEditor(new SpinnerEditor(values)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); DefaultTableModel model = (DefaultTableModel) table.getModel(); model.addColumn("A", new Object[] { "item1" }); model.addColumn("B", new Object[] { "item2" }); String[] values = new String[] { "1", "2", "3" }; TableColumn col = table.getColumnModel().getColumn(0); col.setCellEditor(new MyComboBoxEditor(values)); col.setCellRenderer(new MyComboBoxRenderer(values)); }
From source file:ResizeColumnWidth.java
public static void main(String args[]) { final Object rowData[][] = { { "1", "one", "I" }, { "2", "two", "II" }, { "3", "three", "III" } }; final String columnNames[] = { "#", "English", "Roman" }; final JTable table = new JTable(rowData, columnNames); JScrollPane scrollPane = new JScrollPane(table); JFrame frame = new JFrame("Resizing Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(scrollPane, BorderLayout.CENTER); TableColumn column = null;/* w ww . j av a2 s .c o m*/ for (int i = 0; i < 3; i++) { column = table.getColumnModel().getColumn(i); if (i == 2) { column.setPreferredWidth(100); //sport column is bigger } else { column.setPreferredWidth(50); } } frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void setPrefColumnWidth(JTable table, int index, int width) { table.getColumnModel().getColumn(index).setMinWidth(width); table.getColumnModel().getColumn(index).setPreferredWidth(width); }
From source file:Main.java
public static void setColumnWidth(JTable table, int index, int width) { table.getColumnModel().getColumn(index).setMinWidth(width); table.getColumnModel().getColumn(index).setMaxWidth(width); table.getColumnModel().getColumn(index).setPreferredWidth(width); }
From source file:Main.java
public static void insertComponentInColumn(JTable jTable, int col, JComponent jComponent) { TableColumn sportColumn = jTable.getColumnModel().getColumn(col); if (jComponent instanceof JComboBox) { sportColumn.setCellEditor(new DefaultCellEditor((JComboBox) jComponent)); } else if (jComponent instanceof JCheckBox) { sportColumn.setCellEditor(new DefaultCellEditor((JCheckBox) jComponent)); } else if (jComponent instanceof JTextField) { sportColumn.setCellEditor(new DefaultCellEditor((JTextField) jComponent)); }// w w w.ja v a 2 s . co m }
From source file:Main.java
public static void removeTableColumn(JTable table, String columnIdentifier) { try {/*from w w w.j a va 2 s .c o m*/ TableColumn column = table.getColumn(columnIdentifier); table.getColumnModel().removeColumn(column); } catch (Exception ex) { } }