if (SwingUtilities.isLeftMouseButton(ev) && (ev.getClickCount() == 2)) {
editAction.actionPerformed(null);
}
}
});
tableList.addMouseListener(new PopupListener(tableList, popupMenu) {
protected void checkPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
Point p = new Point(e.getX(), e.getY());
int idx = tableList.rowAtPoint(p);
int[] rows = tableList.getSelectedRows();
boolean inSelection = false;
for (int i = 0; i < rows.length; i++) {
if (rows[i] == idx) {
inSelection = true;
break;
}
}
if (!inSelection && (idx > -1)) {
tableList.setRowSelectionInterval(idx, idx);
}
this.popupMenu.show(component, e.getX(), e.getY());
}
}
});
JPopupMenu tableHeaderMenu = new JPopupMenu();
JMenuItem optimizeColumnWidths = new JMenuItem("Optimal Column Widths");
optimizeColumnWidths.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tableList.optimizeWidths(4);
}
});
tableHeaderMenu.add(optimizeColumnWidths);
tableList.getTableHeader().addMouseListener(new PopupListener(tableList.getTableHeader(), tableHeaderMenu));
tableList.sortByColumn(0);
JScrollPane scrollPane = new JScrollPane(tableList);
scrollPane.getViewport().setBackground(UIManager.getColor("Table.background"));
scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
scrollPane.getViewport().addMouseListener(new PopupListener(tableList, popupMenu));
Container c = getContentPane();
c.add(BorderLayout.NORTH, toolBar);
c.add(BorderLayout.CENTER, scrollPane);