0

Currently in a Jtable there is a space for a name and then a combobox in each column header. When the header name is clicked I would like the default sorting to still take place but when the combobox is clicked I would like it to not sort.

I've tried consuming the mouseclick event when the combobox is clicked but the AWT event handlers have already received the event before my listener.

TableRowSorter is declared as such:

TableRowSorter<TableModel> tableRowSorter = (TableRowSorter<TableModel>) mainTable.getRowSorter();
    tableRowSorter.addRowSorterListener(new RowSorterListener() {
        @Override
        public void sorterChanged(RowSorterEvent e) {
            if (!(mainTable.getSelectedRow() < 0)) {
                Rectangle r = mainTable.getCellRect(mainTable.getSelectedRow(), 0, true);
                Point p = mainScrollPane.getViewport().getViewPosition();
                r.setLocation(r.x, r.y - p.y);
                mainScrollPane.getViewport().scrollRectToVisible(r);
            }
        }
    });

//Section for popupmenu located in jtable class
    aggregationMenu = new JPopupMenu();
    aggregationMenu.setInvoker(this);
    for (AggregationType type : AggregationType.values()) {
        if (type == AggregationType.GROUP)
            continue;
        JMenuItem mi = new JMenuItem();
        mi.setText(type.toString());
        mi.addActionListener(this);
        aggregationMenu.add(mi);
    }
  • which combobox? anyway, confused about the code snippet - what is that supposed to do? and how it is related to sorting (or not)? – kleopatra Jul 25 '13 at 15:03
  • its just where the sorter is being declared, pretty much there is the name in the header and then below is a combobox, I cant seem to get the sorting disabled on the combobox – Joshua Lockhart Jul 25 '13 at 15:35
  • did an edit to my main post – Joshua Lockhart Jul 25 '13 at 15:44
  • 1
    still no use (and partly incorrcect: typicall setInvoker isn't called directly) - show a SSCCE that demonstrates what you are doing and what doesn't work as you expect it – kleopatra Jul 25 '13 at 15:56
  • @kleopatra has adduced some important caveats in the accepted answer to this related [example](http://stackoverflow.com/q/7137786/230513). – trashgod Jul 25 '13 at 16:56

0 Answers0