0

Currently every header contains the name of the column and ocassionally a combo box below it. Whenever the combo box is clicked the jtable automatically sort. Is there a simple way to disable sorting for just the combo box clicks while preserving the rest of the header to sort on click.

I have been suggested JXTable but am fearful that it will cause more problems than it would fix.

Any help is appreciated.

  • http://stackoverflow.com/questions/3312953/how-can-you-disable-all-sorting-code-in-jtable-in-1-6 gives some information but not exactly what you want. – Lee Meador Apr 30 '13 at 16:08
  • I'm not sure what you are saying... well I kind of am. Could you offer some code of the project? – James Manes Apr 30 '13 at 16:18
  • the code is sort of spread out (should be cleaned up but that is another issue). I want to maintain the sort feature on the rest of the header but ignore sorting for the combo box. Not quite sure how to override the JTable's sort. – Joshua Lockhart Apr 30 '13 at 16:33

1 Answers1

0

Try something like:

public class SortFilterTableHeaderUI extends BasicTableHeaderUI {

    private Component filteredComponent;

    @Override
    protected MouseInputListener createMouseInputListener() {
        return new MouseInputHandler() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (!filteredComponent.contains(e.getPoint()))
                    super.mouseClicked(e);
            }
        };
    }
}

Other option is override JTAbleHeader.columnAtPoint(Point point) and return -1 if the combo contains the point.

Jose Luis Martin
  • 10,459
  • 1
  • 37
  • 38