Example usage for javax.swing.table JTableHeader removeMouseListener

List of usage examples for javax.swing.table JTableHeader removeMouseListener

Introduction

In this page you can find the example usage for javax.swing.table JTableHeader removeMouseListener.

Prototype

public synchronized void removeMouseListener(MouseListener l) 

Source Link

Document

Removes the specified mouse listener so that it no longer receives mouse events from this component.

Usage

From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java

@Override
public void setSortable(boolean enable) {
    super.setSortable(enable);

    JTableHeader header = getTableHeader();
    if (enable) {
        if (treeTableSortAdapter == null) {
            treeTableSortAdapter = new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    if (SwingUtilities.isLeftMouseButton(e)) {
                        JTableHeader h = (JTableHeader) e.getSource();
                        TableColumnModel columnModel = getColumnModel();

                        int viewColumn = h.columnAtPoint(e.getPoint());
                        int column = columnModel.getColumn(viewColumn).getModelIndex();

                        if (column != -1) {
                            beforeSort();

                            // Toggle sort order (ascending <-> descending)
                            SortableTreeTableModel model = (SortableTreeTableModel) getTreeTableModel();
                            model.setColumnAndToggleSortOrder(column);

                            // Set sorting icon and current column index
                            ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer())
                                    .setSortingIcon(model.getSortOrder());
                            ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer())
                                    .setColumnIndex(column);

                            saveSortPreferences(column);

                            afterSort();
                        }/*from   ww w. j  ava2  s  .c om*/
                    }
                }
            };
            header.addMouseListener(treeTableSortAdapter);
        }
    } else {
        if (treeTableSortAdapter != null) {
            header.removeMouseListener(treeTableSortAdapter);
            treeTableSortAdapter = null;
        }
    }
}