Issue Details (XML | Word | Printable)

Key: SWINGX-1558
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Trivial Trivial
Assignee: kleopatra
Reporter: robin_stevens
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.

JXTableHeader: add extra getColumnToolTipText method

Created: 06/May/13 10:12 AM   Updated: 19/Jun/13 10:09 AM   Resolved: 19/Jun/13 10:09 AM
Component/s: Table
Affects Version/s: None
Fix Version/s: 1.6.6

Time Tracking:
Not Specified

Participants: kleopatra and robin_stevens

 Description  « Hide

The current signature of the getColumnToolTipText is

protected String getColumnToolTipText(MouseEvent event)

It would be nice if there was an extra method

protected String getColumnToolTipText(TableColumnExt tableColumn)

Typically if you want to override the tooltip you need access to the table column. This means you currently have to duplicate the code that is present in getColumnToolTipText

My proposal is to adjust the current implementation of getColumnToolTipText to

protected String getColumnToolTipText(MouseEvent event) {
        if (getXTable() == null) return null;
        int column = columnAtPoint(event.getPoint());
        if (column < 0) return null;
        TableColumnExt columnExt = getXTable().getColumnExt(column);
        return columnExt != null ? getColumnToolTipText( columnExt ) : null;
    protected String getColumnToolTipText( TableColumnExt tableColumn ){
      return tableColumn.getToolTipText();

This should allow you to only override the getColumnToolTipText( TableColumnExt tableColumn ) method without having to duplicate the rest of the code in the getColumnToolTipText(MouseEvent event) method

kleopatra added a comment - 18/Jun/13 09:51 AM

hmm .. can't quite think of a use-case (brain still a bit sluggish after vacation - why do you want to not return the column's tooltip? Could you elaborate a bit?

But inclined to improve the factoring along your suggestion, maybe additionally separating the logic completely into a new method which returns the columnExt at the mouseEvent, need to think a bit.


robin_stevens added a comment - 18/Jun/13 10:03 AM

The use-case we have is that the tooltip is specified by the TableModel. Our TableModel is a sort of wrapper of our own "model" where the tooltip can be retrieved from our "model".

We have one table where the TableModel is replaced at run-time based on some external parameters. As such, it is impossible to define the tooltips of the table in advance. Instead we retrieve them from our TableModel. In code, we have the following

private static class TooltipTableHeader extends JXTableHeader {

    private final TableModel fTableModel;

    public TooltipTableHeader( TableColumnModel aColumnModel, TableModel aTableModel ) {
      super( aColumnModel );
      fTableModel = aTableModel;

    public String getToolTipText( MouseEvent event ) {
      int viewIndex = getColumnModel().getColumnIndexAtX( event.getX() );
      int modelIndex = getColumnModel().getColumn( viewIndex ).getModelIndex();
      if ( fTableModel instanceof IExtendedTableModel ) {
        return ( ( IExtendedTableModel ) fTableModel ).getColumnTooltipText( modelIndex );
      return fTableModel.getColumnName( modelIndex );

As you can see, we need to duplicate the conversion from event to column. On the other hand, the workaround is so trivial and the use-case perhaps so limited that it does not justify to add API.

kleopatra added a comment - 19/Jun/13 10:09 AM

fixed revision #4296

  • added public api to get the tableColumn at a location
  • added protected api to get the tooltiptext at a column
  • changed getColumnToolTipText(MouseEvent) to use both
  • added visual tests

Basically, went along your suggestion While doing so, discovered Issue SWINGX-1560 which is fixed also. JXTableHeaderVisualCheck has your use-case as an example.

Thanks for the thorough report