JTableEx extends JTable to provide auto-tooltips.
| 44 | * |
| 45 | */ |
| 46 | public class JTableEx extends JTable |
| 47 | { |
| 48 | /** Constant for a double click action event. */ |
| 49 | public static final int ACTION_DOUBLECLICK = 2042; |
| 50 | private boolean sortingEnabled; |
| 51 | |
| 52 | /** |
| 53 | * Constructor |
| 54 | */ |
| 55 | JTableEx() |
| 56 | { |
| 57 | this(null, null, null); |
| 58 | } |
| 59 | |
| 60 | private JTableEx(TableModel tm, TableColumnModel tcm, ListSelectionModel lsm) |
| 61 | { |
| 62 | super(tm, tcm, lsm); |
| 63 | setFillsViewportHeight(true); |
| 64 | setDefaultRenderer(BigDecimal.class, new TableCellUtilities.AlignRenderer(SwingConstants.RIGHT)); |
| 65 | setDefaultRenderer(Float.class, new TableCellUtilities.AlignRenderer(SwingConstants.RIGHT)); |
| 66 | setDefaultRenderer(Integer.class, new TableCellUtilities.AlignRenderer(SwingConstants.RIGHT)); |
| 67 | installDoubleClickListener(); |
| 68 | } |
| 69 | |
| 70 | private void installDoubleClickListener() |
| 71 | { |
| 72 | addMouseListener(new MouseAdapter() |
| 73 | { |
| 74 | @Override |
| 75 | public void mouseClicked(MouseEvent e) |
| 76 | { |
| 77 | if (e.getComponent().isEnabled() && e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) |
| 78 | { |
| 79 | Point p = e.getPoint(); |
| 80 | int row = convertRowIndexToModel(rowAtPoint(p)); |
| 81 | int column = convertColumnIndexToModel(columnAtPoint(p)); |
| 82 | Object value = getModel().getValueAt(row, column); |
| 83 | fireActionEvent(JTableEx.this, ACTION_DOUBLECLICK, String.valueOf(value)); |
| 84 | } |
| 85 | } |
| 86 | }); |
| 87 | } |
| 88 | |
| 89 | private void fireActionEvent(Object value, int id, String command) |
| 90 | { |
| 91 | ActionEvent e = null; |
| 92 | // Guaranteed to return a non-null array |
| 93 | Object[] listeners = listenerList.getListenerList(); |
| 94 | // Process the listeners last to first, notifying |
| 95 | // those that are interested in this event |
| 96 | for (int i = listeners.length - 2; i >= 0; i -= 2) |
| 97 | { |
| 98 | if (listeners[i] == ActionListener.class) |
| 99 | { |
| 100 | // Lazily create the event: |
| 101 | if (e == null) |
| 102 | { |
| 103 | e = new ActionEvent(value, id, command); |
nothing calls this directly
no outgoing calls
no test coverage detected