private void initComponents() { jbAdd = new JButton( new ImageIcon( Toolkit.getDefaultToolkit() .createImage( getClass().getResource(res.getString("JPolicyInformation.jbAdd.image"))))); jbAdd.setMargin(new Insets(2, 2, 0, 0)); jbAdd.setToolTipText(res.getString("JPolicyInformation.jbAdd.tooltip")); jbAdd.setMnemonic(res.getString("JPolicyInformation.jbAdd.mnemonic").charAt(0)); jbAdd.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); addPressed(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } }); jbEdit = new JButton( new ImageIcon( Toolkit.getDefaultToolkit() .createImage( getClass().getResource(res.getString("JPolicyInformation.jbEdit.image"))))); jbEdit.setMargin(new Insets(2, 2, 0, 0)); jbEdit.setToolTipText(res.getString("JPolicyInformation.jbEdit.tooltip")); jbEdit.setMnemonic(res.getString("JPolicyInformation.jbEdit.mnemonic").charAt(0)); jbEdit.setEnabled(false); jbEdit.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); editPressed(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } }); jbRemove = new JButton( new ImageIcon( Toolkit.getDefaultToolkit() .createImage( getClass() .getResource(res.getString("JPolicyInformation.jbRemove.image"))))); jbRemove.setMargin(new Insets(2, 2, 0, 0)); jbRemove.setToolTipText(res.getString("JPolicyInformation.jbRemove.tooltip")); jbRemove.setMnemonic(res.getString("JPolicyInformation.jbRemove.mnemonic").charAt(0)); jbRemove.setEnabled(false); jbRemove.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); removePressed(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } }); jpPolicyInformationButtons = new JPanel(); jpPolicyInformationButtons.setLayout( new BoxLayout(jpPolicyInformationButtons, BoxLayout.Y_AXIS)); jpPolicyInformationButtons.add(Box.createVerticalGlue()); jpPolicyInformationButtons.add(jbAdd); jpPolicyInformationButtons.add(Box.createVerticalStrut(3)); jpPolicyInformationButtons.add(jbEdit); jpPolicyInformationButtons.add(Box.createVerticalStrut(3)); jpPolicyInformationButtons.add(jbRemove); jpPolicyInformationButtons.add(Box.createVerticalGlue()); PolicyInformationTableModel policyInformationTableModel = new PolicyInformationTableModel(); jtPolicyInformation = new JKseTable(policyInformationTableModel); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(policyInformationTableModel); sorter.setComparator(0, new PolicyInformationTableModel.PolicyInformationComparator()); jtPolicyInformation.setRowSorter(sorter); jtPolicyInformation.setShowGrid(false); jtPolicyInformation.setRowMargin(0); jtPolicyInformation.getColumnModel().setColumnMargin(0); jtPolicyInformation.getTableHeader().setReorderingAllowed(false); jtPolicyInformation.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS); jtPolicyInformation.setRowHeight(Math.max(18, jtPolicyInformation.getRowHeight())); for (int i = 0; i < jtPolicyInformation.getColumnCount(); i++) { TableColumn column = jtPolicyInformation.getColumnModel().getColumn(i); column.setHeaderRenderer( new PolicyInformationTableHeadRend( jtPolicyInformation.getTableHeader().getDefaultRenderer())); column.setCellRenderer(new PolicyInformationTableCellRend()); } ListSelectionModel selectionModel = jtPolicyInformation.getSelectionModel(); selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); selectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { updateButtonControls(); } } }); jtPolicyInformation.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { maybeEditPolicyInformation(evt); } }); jtPolicyInformation.addKeyListener( new KeyAdapter() { boolean deleteLastPressed = false; @Override public void keyPressed(KeyEvent evt) { // Record delete pressed on non-Macs if (!OperatingSystem.isMacOs()) { deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE; } } @Override public void keyReleased(KeyEvent evt) { // Delete on non-Mac if delete was pressed and is now released if (!OperatingSystem.isMacOs() && deleteLastPressed && evt.getKeyCode() == KeyEvent.VK_DELETE) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); deleteLastPressed = false; removeSelectedPolicyInformation(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } } @Override public void keyTyped(KeyEvent evt) { // Delete on Mac if back space typed if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); removeSelectedPolicyInformation(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } } }); jspPolicyInformation = PlatformUtil.createScrollPane( jtPolicyInformation, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); jspPolicyInformation.getViewport().setBackground(jtPolicyInformation.getBackground()); this.setLayout(new BorderLayout(5, 5)); setPreferredSize(new Dimension(250, 150)); add(jspPolicyInformation, BorderLayout.CENTER); add(jpPolicyInformationButtons, BorderLayout.EAST); populate(); }