Benches Uncategorized

3

Sort indicator missing on JTable in OSX

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I just added column sorting to the JTables in my app. On windows it works as advertised. On OSX, the table is sorted when I click the headers, but the sort indicator does not show up. So the first time the user clicks a header for a column that's already sorted, it looks like nothing happens. On Windows, they see the sort indicator appear, so they know their action had an effect. Plus, they can see the sort direction at any time.

Is there perhaps a property I need to set to make the sort indicator appear in OSX? Or is this the way it was designed for OSX?

3 replies

Sign in or join Beachball Help to reply.

  1. 0

    laurent demaret

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hello MidnightJava,

    I must admit my app works like a Windows® one ! At least for tableView sorting when clicking the header. Little triangle appears as soon as I click a header and reflect the direction of the sort.

    Maybe it's because of the way I'm doing my sort ?

    - (void)tableView:(NSTableView *)tableView
    sortDescriptorsDidChange:(NSArray *)oldDescriptors
    {
    NSArray *newDescriptors = [tableView sortDescriptors];
    [mutableArray sortUsingDescriptors:newDescriptors];
    [tableView reloadData];
    }

    in my tableView delegate file and Sort Key + Selector fields filled as should be in IB. But I have exactly same behavior when done via ArrayController.

    How do you do yours ? Maybe it's for iPhone (never heard about JTables), I don't know for iPhone …

  2. 0

    MidnightJava

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I should have mentioned, it's the Java implementation on OSX where the problem occurs. JTable is the Java implementation of an emulated native table control.

    As revealed to me on the [email protected] list, there are some client properties that can be set to specify specific Cocoa behaviors in the Java implementation of certain JComponent classes. The properties are listed and their usage explained here.

    http://developer.apple.com/mac/library/technotes/tn2007/tn2196.html#GENID1

    An Apple engineer pointed out that these are workarounds, as OSX should work out of the box same as Windows. I'll submit a bug report, per his suggestion.

    Here's my implementation of the fix for the problem I encouontered. The following method is called from the JTable constructor, so the methods invoked in it are JTable methods.

    private void setupRowSorter() {
    setAutoCreateRowSorter(true);//Java6 only. For Java 5, create a TableRowSorter and add it to the JTable
    getTableHeader().addMouseListener(new MouseListener() {
    @Override
    public void mouseClicked(MouseEvent e) {
    getTableHeader().putClientProperty("JTableHeader.selectedColumn", getTableHeader().columnAtPoint(e.getPoint()));
    if (getTableHeader().getClientProperty("JTableHeader.sortDirection") == null) {
    getTableHeader().putClientProperty("JTableHeader.sortDirection", "ascending");
    } else if (getTableHeader().getClientProperty("JTableHeader.sortDirection").equals("ascending")) {
    getTableHeader().putClientProperty("JTableHeader.sortDirection", "decending");//misspelling is required, per Apple documentation
    } else {
    getTableHeader().putClientProperty("JTableHeader.sortDirection", "ascending");
    }
    }
    @Override
    public void mouseEntered(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }
    @Override
    public void mouseExited(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }
    @Override
    public void mousePressed(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }
    @Override
    public void mouseReleased(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }

    });
    }

  3. 0

    laurent demaret

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Well I should have guessed it because of the J in JTable 😟

    On the link you give I read +This property has no effect if JTableHeader.selectedColumn has not been specified.+.

    If I was you I would log or use debugger (if available) to see if the method get it right (it seems to but rather be sure) and if it does and the arrow does not appear I would fill a bug report. I don't know enough of Java to help you more, sorry