List of usage examples for javax.swing JTable setCellSelectionEnabled
@BeanProperty(visualUpdate = true, description = "Select a rectangular region of cells rather than rows or columns.") public void setCellSelectionEnabled(boolean cellSelectionEnabled)
From source file:pcgen.gui2.dialog.PostLevelUpDialog.java
private void initComponents() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); Container pane = getContentPane(); pane.setLayout(new BorderLayout()); JTable table = new JTable(tableModel) { @Override//from w ww. j a v a 2 s . c om public TableCellEditor getCellEditor(int row, int column) { if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) {//TODO: the max roll should be calculated in a different manner String hd = levels.getClassTaken(levels.getElementAt(row + oldLevel)).getHD(); int max = NumberUtils.toInt(hd); return new SpinnerEditor(new SpinnerNumberModel(1, 1, max, 1)); } return super.getCellEditor(row, column); } @Override public TableCellRenderer getCellRenderer(int row, int column) { if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) { return new SpinnerRenderer(); } return super.getCellRenderer(row, column); } }; table.setCellSelectionEnabled(false); table.setRowHeight(new JSpinner().getPreferredSize().height); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); JScrollPane scrollPane = new JScrollPane(table); pane.add(scrollPane, BorderLayout.CENTER); Box box = Box.createHorizontalBox(); box.add(Box.createHorizontalGlue()); JButton button = new JButton(LanguageBundle.getString("in_close")); //$NON-NLS-1$ button.setMnemonic(LanguageBundle.getMnemonic("in_mn_close")); //$NON-NLS-1$ button.setActionCommand("Close"); //$NON-NLS-1$ button.addActionListener(this); box.add(button); pane.add(box, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { //Make sure to remove the listeners so that the garbage collector can //dispose of this dialog and prevent a memory leak levels.removeHitPointListener(tableModel); } }); Utility.installEscapeCloseOperation(this); }