Override mousePressedHandler BasicTableUI (JTable)

Viewed 261

I want to adjust my JTable such that when I start editing a cell and then select a range of cells, the cell editor doesn't disappear, but instead changes it's value to the "current selection".

I already have a custom ListSelectionListener that listens for changes in the selections and creates an Range object from that which can be converted to a String (eg. A1:C3), but I'm looking for a way to hook in at the moment where the cell editor is being stopped / the selection event starts, so that I can prevent the default behaviour and stay in editing mode while selecting cells. Does any one have an idea?

Edit: I have come a little bit further. When throwing an error in the removeEditor() method, I get the following stack trace:

at GUI.STable.removeEditor(STable.java:71)
at javax.swing.JTable.editingStopped(JTable.java:4724)
at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:141)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:368)
at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:233)
at GUI.STable$CustomTableCellEditor.stopCellEditing(STable.java:119)
at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:1010)

This leads to the mousePressed event in BasicTableUI, which indeed closes the current editor:

if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
    Component editorComponent = table.getEditorComponent();
    if (editorComponent != null && !editorComponent.hasFocus()) {
        SwingUtilities2.compositeRequestFocus(editorComponent);
    }
    return;
}

But how can I override this mousePressed handler in BasicTableUI?

0 Answers
Related