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:Main.java
public static void main(String[] argv) { JFrame demoFrame = new JFrame("Variable Row Height Table Demo"); StringTableModel imageTableModel = new StringTableModel(); JTable imageTable = new JTable(imageTableModel); imageTable.getColumnModel().getColumn(0).setCellRenderer(new VariableRowHeightRenderer()); demoFrame.getContentPane().add(new JScrollPane(imageTable)); demoFrame.pack();/* ww w .ja v a 2 s . com*/ demoFrame.setVisible(true); }
From source file:ColorTableModel.java
public static void main(String args[]) { JFrame frame = new JFrame("Editable Color Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TableModel model = new ColorTableModel(); JTable table = new JTable(model); TableColumn column = table.getColumnModel().getColumn(3); TableCellEditor editor = new ColorChooserEditor(); column.setCellEditor(editor);// ww w . j a v a2 s.c o m JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
From source file:ComboTableCellRenderer.java
public static void main(String args[]) { Color choices[] = { Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.BLUE, Color.MAGENTA }; ComboTableCellRenderer renderer = new ComboTableCellRenderer(); JComboBox comboBox = new JComboBox(choices); comboBox.setRenderer(renderer);/*from w w w . j ava 2 s . com*/ TableCellEditor editor = new DefaultCellEditor(comboBox); JFrame frame = new JFrame("Editable Color Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TableModel model = new ColorTableModel(); JTable table = new JTable(model); TableColumn column = table.getColumnModel().getColumn(1); column.setCellRenderer(renderer); column.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Editable Color Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TableModel model = new ColorTableModel(); JTable table = new JTable(model); TableColumn column = table.getColumnModel().getColumn(2); ComboTableCellRenderer renderer = new ComboTableCellRenderer(); column.setCellRenderer(renderer);//from w ww .j a va2 s . c o m TableCellEditor editor = new ColorChooserEditor(); column.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
From source file:TableSample2.java
public static void main(String args[]) { Object rows[][] = { { "one", "ichi - \u4E00", "un" }, { "two", "ni - \u4E8C", "deux" }, { "three", "san - \u4E09", "trois" }, { "four", "shi - \u56DB", "quatre" }, { "five", "go - \u4E94", "cinq" }, { "six", "roku - \u516D", "treiza" }, { "seven", "shichi - \u4E03", "sept" }, { "eight", "hachi - \u516B", "huit" }, { "nine", "kyu - \u4E5D", "neuf" }, { "ten", "ju - \u5341", "dix" } }; Object options[] = { "un", "deux", "trois", "quatre", "cinq", "treiza", "sept", "huit", "neuf", "dix" }; JComboBox comboBox = new JComboBox(options); comboBox.setMaximumRowCount(4);//w w w . ja va 2 s . c o m TableCellEditor editor = new DefaultCellEditor(comboBox); Object headers[] = { "English", "Japanese", "French" }; JFrame frame = new JFrame("JTable Anatomy"); class CustomTableModel extends DefaultTableModel { public CustomTableModel(Object rowData[][], Object columnNames[]) { super(rowData, columnNames); } public Class getColumnClass(int col) { Vector v = (Vector) dataVector.elementAt(0); return v.elementAt(col).getClass(); } public boolean isCellEditable(int row, int col) { return true; } } JTable table = new JTable(new DefaultTableModel(rows, headers)); // ColumnModelUtilities.removeHeaders(table.getColumnModel()); table.getColumnModel().getColumn(2).setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(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[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TableModel model = new ColorTableModel(); JTable table = new JTable(model); TableColumn column = table.getColumnModel().getColumn(2); ComboTableCellRenderer renderer = new ComboTableCellRenderer(); column.setCellRenderer(renderer);//from w w w. j av a2s. c om TableCellEditor editor = new ColorChooserEditor(); column.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
From source file:EditableColorColumn.java
public static void main(String args[]) { Color choices[] = { Color.red, Color.orange, Color.yellow, Color.green, Color.blue, Color.magenta }; ComboTableCellRenderer renderer = new ComboTableCellRenderer(); JComboBox comboBox = new JComboBox(choices); comboBox.setRenderer(renderer);/*from w w w.ja v a 2 s. c o m*/ TableCellEditor editor = new DefaultCellEditor(comboBox); JFrame frame = new JFrame("Editable Color Table"); TableModel model = new ColorTableModel(); JTable table = new JTable(model); TableColumn column = table.getColumnModel().getColumn(3); column.setCellRenderer(renderer); 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 { DefaultTableModel model = new MyDefaultTableModel(); JTable table = new JTable(model); table.setModel(model);// w ww . j av a 2 s. co m model.addColumn("Col1"); model.addColumn("Col2"); model.addColumn("Col3"); model.addRow(new Object[] { "v1" }); table.removeColumn(table.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.addColumn("Col1"); model.addColumn("Col2"); table.getTableHeader().getColumnModel().getColumn(1).setHeaderRenderer(new IconHeaderRenderer()); table.getColumnModel().getColumn(1).setHeaderValue(new TextAndIcon("Col2", new ImageIcon("icon.gif"))); }
From source file:EditableTable.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String[] columnTitles = { "First Name", "Last Name", "Weight (lb)", "Blood Group", "Age>20yrs" }; Object[][] dataEntries = { { "Saravan", "Pantham", new Integer(50), "B", new Boolean(false) }, { "Eric", "", new Integer(180), "O", new Boolean(true) }, { "John", "", new Integer(120), "AB", new Boolean(false) }, { "Mathew", "", new Integer(140), "A", new Boolean(true) }, }; TableModel model = new EditableTableModel(columnTitles, dataEntries); JTable table = new JTable(model); table.createDefaultColumnsFromModel(); String[] bloodGroups = { "A", "B", "AB", "O" }; JComboBox comboBox = new JComboBox(bloodGroups); table.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBox)); frame.add(new JScrollPane(table)); frame.setSize(300, 200);//from w w w . j ava2s. c o m frame.setVisible(true); }