JComponent () { myTableModel = new MyTableModel(); myTable = new JBTable(myTableModel); myTable.setSurrendersFocusOnKeystroke(true); MyTableRenderer renderer = new MyTableRenderer(); TableColumnModel columnModel = myTable.getColumnModel(); columnModel.getColumn(CHECKED_COLUMN).setCellRenderer(new BooleanTableCellRenderer()); columnModel.getColumn(FIELD_COLUMN).setCellRenderer(renderer); columnModel.getColumn(GETTER_COLUMN).setCellRenderer(renderer); columnModel.getColumn(SETTER_COLUMN).setCellRenderer(renderer); TableUtil.setupCheckboxColumn(columnModel.getColumn(CHECKED_COLUMN)); myTable.setPreferredScrollableViewportSize(JBUI.size(550, -1)); myTable.setVisibleRowCount(12); myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable); // JLabel label = new JLabel("Fields to Encapsulate"); // CompTitledBorder titledBorder = new CompTitledBorder(label); JPanel panel = new JPanel(new BorderLayout()); Border border = IdeBorderFactory.createTitledBorder( JavaRefactoringBundle.message("encapsulate.fields.fields.to.encapsulate.border.title"), false); panel.setBorder(border); panel.add(scrollPane); // make ESC and ENTER work when focus is in the table myTable.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TableCellEditor editor = myTable.getCellEditor(); if (editor != null) { editor.cancelCellEditing(); } else { doCancelAction(); } } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); // make SPACE check/uncheck selected rows @NonNls InputMap inputMap = myTable.getInputMap(); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable"); @NonNls ActionMap actionMap = myTable.getActionMap(); actionMap.put("enable_disable", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (myTable.isEditing()) return; int[] rows = myTable.getSelectedRows(); if (rows.length > 0) { boolean valueToBeSet = false; for (int row : rows) { if (!myCheckedMarks[row]) { valueToBeSet = true; break; } } for (int row : rows) { myCheckedMarks[row] = valueToBeSet; } myTableModel.fireTableRowsUpdated(rows[0], rows[rows.length - 1]); TableUtil.selectRows(myTable, rows); } } } ); // make ENTER work when the table has focus inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "invokeImpl"); actionMap.put("invokeImpl", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { TableCellEditor editor = myTable.getCellEditor(); if (editor != null) { editor.stopCellEditing(); } else { clickDefaultButton(); } } } ); return panel; }