List of usage examples for javax.swing.table TableColumn setCellEditor
@BeanProperty(description = "The editor to use for cell values.") public void setCellEditor(TableCellEditor cellEditor)
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); TableColumn col = table.getColumnModel().getColumn(0); col.setCellEditor(new MyTableCellEditor()); }
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:Main.java
public static void main(String[] argv) { DefaultTableModel model = new DefaultTableModel() { public Class getColumnClass(int columnIndex) { Object o = getValueAt(0, columnIndex); if (o == null) { return Object.class; } else { return o.getClass(); }//from ww w. j a v a 2s .c o m } }; JTable table = new JTable(model); model.addColumn("Boolean", new Object[] { Boolean.TRUE }); model.addColumn("Date", new Object[] { new Date() }); model.addColumn("Double", new Object[] { new Double(Math.PI) }); model.addColumn("Float", new Object[] { new Float(1.2) }); model.addColumn("Icon", new Object[] { new ImageIcon("icon.gif") }); model.addColumn("Number", new Object[] { new Integer(1) }); model.addColumn("Object", new Object[] { "object" }); Enumeration e = table.getColumnModel().getColumns(); TableColumn col = (TableColumn) e.nextElement(); col.setCellRenderer(table.getDefaultRenderer(Boolean.class)); col.setCellEditor(table.getDefaultEditor(Boolean.class)); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.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);/*w w w . ja va2 s . c o m*/ 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: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); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150);/*from www . ja v a 2 s. c om*/ 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);// w w w. j a va 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 args[]) { JFrame frame = new JFrame(); frame.setSize(450, 250);/*from ww w . j a v a 2s .c om*/ JTable table = new JTable(5, 5); TableColumn testColumn = table.getColumnModel().getColumn(0); JComboBox<String> comboBox = new JComboBox<>(); comboBox.addItem("This"); comboBox.addItem("is"); comboBox.addItem("a"); comboBox.addItem("Sample program"); testColumn.setCellEditor(new DefaultCellEditor(comboBox)); frame.add(table); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 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);/* w ww .j a v a2 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: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);/* w w w . j a va 2 s . 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); }