public TableCellRenderFrame() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); TableModel model = new PlanetTableModel(); JTable table = new JTable(model); table.setRowSelectionAllowed(false); // set up renderers and editors table.setDefaultRenderer(Color.class, new ColorTableCellRenderer()); table.setDefaultEditor(Color.class, new ColorTableCellEditor()); JComboBox<Integer> moonCombo = new JComboBox<>(); for (int i = 0; i <= 20; i++) moonCombo.addItem(i); TableColumnModel columnModel = table.getColumnModel(); TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN); moonColumn.setCellEditor(new DefaultCellEditor(moonCombo)); moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class)); moonColumn.setHeaderValue(new ImageIcon(getClass().getResource("Moons.gif"))); // show table table.setRowHeight(100); add(new JScrollPane(table), BorderLayout.CENTER); }
/** Create a new, empty property sheet. */ public PropertySheet() { super(new EnhancedTable()); this.getPreferredSize(); props = new ForClassPropertyList(); // Add bean change event listener props.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { // XXX Should I fire a 'stop editing' event here? refresh(); } }); // Add table JTable table = getTable(); MyTableModel tableModel = new MyTableModel(); table.setModel(tableModel); table.setDefaultRenderer(InstancePropertyDescriptor.class, new MyCellRenderer()); table.setDefaultEditor(InstancePropertyDescriptor.class, new MyCellEditor()); }