List of usage examples for javax.swing JTable setDefaultEditor
public void setDefaultEditor(Class<?> columnClass, TableCellEditor editor)
TableColumn
. From source file:de.codesourcery.eve.skills.ui.spreadsheet.SpreadSheetTableModel.java
public static void main(String[] args) { final ITableFactory cellFactory = new ITableFactory() { @Override/*from w w w . java 2s . c om*/ public ITableCell createEmptyCell(int row, int column) { return new SimpleCell(); } @Override public TableRow createRow(SpreadSheetTableModel tableModel) { return new TableRow(tableModel); } }; final SpreadSheetTableModel model = new SpreadSheetTableModel(cellFactory); final JTable table = new JTable(model); table.setFillsViewportHeight(true); final JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // table.setPreferredSize( new Dimension(400,200 ) ); table.setBorder(BorderFactory.createLineBorder(Color.black)); frame.getContentPane().add(new JScrollPane(table)); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); model.addRow(new SimpleCell("First row") { public boolean isEditable() { return true; } public void setValue(Object value) { System.out.println("new value: " + value); } }); model.addRow(new SimpleCell("Second row #1"), new SimpleCell("Second row #2")); model.addRow(new SimpleCell("Third row #1"), new SimpleCell("Third row #2"), new SimpleCell("Third row #3")); JTextField tf = new JTextField(); table.setModel(model); table.setDefaultEditor(ITableCell.class, new DefaultCellEditor(tf)); } }); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(model); table.setDefaultEditor(Object.class, new MyEditor()); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); pack();//ww w . ja v a 2 s.c om }
From source file:DefaultCellEditorJTextFieldAlignment.java
public DefaultCellEditorJTextFieldAlignment() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(model); table.setDefaultEditor(Object.class, new MyEditor()); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); pack();/* w ww.j av a 2 s . c o m*/ }
From source file:MainClass.java
public MainClass() { super("Customer Editor Test"); setSize(600, 160);//ww w . j a v a2s . c o m setDefaultCloseOperation(EXIT_ON_CLOSE); MixerModel test = new MixerModel(); JTable jt = new JTable(test); jt.setDefaultRenderer(Volume.class, new VolumeRenderer()); jt.setDefaultEditor(Volume.class, new VolumeEditor()); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:MixerTest2.java
public MixerTest2() { super("Customer Editor Test"); setSize(600, 160);/* ww w. j ava 2 s . c om*/ setDefaultCloseOperation(EXIT_ON_CLOSE); MixerModel test = new MixerModel(); test.dump(); JTable jt = new JTable(test); jt.setDefaultRenderer(Volume.class, new VolumeRenderer()); jt.setDefaultEditor(Volume.class, new VolumeEditor()); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:TableCellRenderTest.java
public TableCellRenderFrame() { setTitle("TableCellRenderTest"); 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 moonCombo = new JComboBox(); for (int i = 0; i <= 20; i++) moonCombo.addItem(i);/*from w w w . j a v a2s . c o m*/ 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("Moons.gif")); // show table table.setRowHeight(100); add(new JScrollPane(table), BorderLayout.CENTER); }
From source file:components.TableFTFEditDemo.java
public TableFTFEditDemo() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);//w ww . ja v a 2s . c om //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Set up stricter input validation for the integer column. table.setDefaultEditor(Integer.class, new IntegerEditor(0, 100)); //If we didn't want this editor to be used for other //Integer columns, we'd do this: //table.getColumnModel().getColumn(3).setCellEditor( // new IntegerEditor(0, 100)); //Add the scroll pane to this panel. add(scrollPane); }
From source file:components.TableDialogEditDemo.java
public TableDialogEditDemo() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);/*from w w w. j a v a 2 s. co m*/ //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Set up renderer and editor for the Favorite Color column. table.setDefaultRenderer(Color.class, new ColorRenderer(true)); table.setDefaultEditor(Color.class, new ColorEditor()); //Add the scroll pane to this panel. add(scrollPane); }
From source file:TableDialogEditDemo.java
public TableDialogEditDemo() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Set up renderer and editor for the Favorite Color column. table.setDefaultRenderer(Color.class, new ColorRenderer(true)); table.setDefaultEditor(Color.class, new ColorEditor()); //Add the scroll pane to this panel. add(scrollPane);/*w w w .j a v a 2 s . c o m*/ }
From source file:MainClass.java
public MainClass() { super("Table With DefaultCellEditor Example"); setSize(500, 300);/*ww w . j a v a2 s .com*/ setDefaultCloseOperation(EXIT_ON_CLOSE); JTable table = new JTable(new AbstractTableModel() { ColorName data[] = { colors[0], colors[1], colors[2], colors[3], colors[4], colors[0], colors[1], colors[2], colors[3], colors[4] }; public int getColumnCount() { return 3; } public int getRowCount() { return 10; } public Object getValueAt(int r, int c) { switch (c) { case 0: return (r + 1) + "."; case 1: return "Some pithy quote #" + r; case 2: return data[r]; } return "Bad Column"; } public Class getColumnClass(int c) { if (c == 2) return ColorName.class; return String.class; } public boolean isCellEditable(int r, int c) { return c == 2; } public void setValueAt(Object value, int r, int c) { data[r] = (ColorName) value; } }); table.setDefaultEditor(ColorName.class, new DefaultCellEditor(new JComboBox(colors))); table.setDefaultRenderer(ColorName.class, new DefaultTableCellRenderer()); table.setRowHeight(20); getContentPane().add(new JScrollPane(table)); }