Setting tooltip for headers of a table.

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Setting tooltip for headers of a table.

Postby pp_dv » Thu Nov 06, 2008 6:46 am

Hello All,

I am trying to set tooltip for the column headers of a table. While doing so, I am losing the previous font, borders and color values of the table. Though I am able to set back the color but not the font and border.

The code is a bit like this:


public class SampeTable extends TableScrollPane{
private JTable _mainTable=null;
public JTable buildTable(){
if (_mainTable == null)
{
_mainTable = this.getMainTable();

//Setting the widths as per column specifications
List<TicketColumn> columnsList= _appControlIntf.getBlotterTableModel().getColumns();
Color color=null;
Font font=null;
for(int i=0;i<columnsList.size();i++)
{
TableColumn tableColumn = null;

switch (getInBlotterTableModel().getColumnType(i))
{
case MultiTableModel.HEADER_COLUMN:
tableColumn = getRowHeaderTable().getColumnModel().getColumn(i);
break;
default:
tableColumn = getMainTable().getColumnModel().getColumn(i - getRowHeaderTable().getColumnCount());
}

tableColumn.setPreferredWidth(columnsList.get(i).getWidth());

// Render the first column as a checkbox
if (i == 0)
{
tableColumn.setCellRenderer(new BooleanCheckBoxCellRenderer());
color = ((BooleanCheckBoxCellRenderer) tableColumn.getCellRenderer()).getBackground();
font = ((BooleanCheckBoxCellRenderer) tableColumn.getCellRenderer()).getFont();
font = font.deriveFont(Font.BOLD);
tableColumn.setCellEditor(new BooleanCheckBoxCellEditor());
}
else
{
JLabel headerRenderer = new DefaultTableCellRenderer();
headerRenderer.setBackground(color);
headerRenderer.setFont(font);
headerRenderer.setToolTipText("Hello");
tableColumn.setHeaderRenderer((TableCellRenderer) headerRenderer);
}
}
initializeTable(_mainTable);
initializeTable(getRowHeaderTable());

}
return _mainTable;

}
private void initializeTable(JTable table)
{
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
((SortableTable) table).setOptimized(true);
JTableHeader header = table.getTableHeader();
header.setBorder(BorderFactory.createRaisedBevelBorder());
header.setFont(header.getFont().deriveFont(java.awt.Font.BOLD));

table.addMouseListener(new MouseListener()
{
public void mouseReleased(MouseEvent e)
{
showPopup(e);
}

public void mousePressed(MouseEvent e)
{
showPopup(e);
}

private void showPopup(MouseEvent e)
{
if (e.isPopupTrigger())
{
getInboundBlotterPopup().show(e.getComponent(), e.getX(), e.getY());
}
}

public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
{
_appControlIntf.showFixMessageBlotter(getSelectedInboundTicketView());
}

}

public void mouseEntered(MouseEvent e)
{
}

public void mouseExited(MouseEvent e)
{
}

});
}
}



With the above code, I am able to set the tooltip text, but the font and border are being compromised. For the column (i=0), the font and borders are fine as I am not using the DefaultCellRenderer. For the rest of the columns the color attribute is being set but not the font. I even tried to set the borders using the setBorder(), but to no avail.

Any help would be appreciated. Let me know if more inputs/code is required.

Regards,
pp_dv
pp_dv
 
Posts: 5
Joined: Thu Nov 06, 2008 6:26 am

Re: Setting tooltip for headers of a table.

Postby JIDE Support » Thu Nov 06, 2008 8:12 am

You don't want to use your own cell renderer for table header as you will never get the same border and style for some L&Fs. Please use an interface called ToolTipSupport we introduced. There is a sample in SortableTableDemo to show you how to use it.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37263
Joined: Sun Sep 14, 2003 10:49 am

Re: Setting tooltip for headers of a table.

Postby pp_dv » Fri Nov 07, 2008 9:10 am

Hello,

Thanks for the reply.

My situation is a bit like this: The _mainTable has a SortableTableModel which recursively nests to a custom table model class. I have made my custom table model class implement ToolTipSupport with necessary implementation. But still when I run my applet, I don't see the tool tip. I have debugged the _mainTable attribute and found that the dataModel attribute was deeply nested to the custom table model class.

I am not sure if I am missing something here.

public class InBlotterTableModel extends DVAbstractBlotterTableModel implements Runnable, LogIDProvider, ToolTipSupport{
///Some code here
public String getToolTipText(int columnIndex)
{
return InboundTicketViewColumns.COLUMNS.get(columnIndex).getName();
}

}


I also tried to add a breakpoint in the InBlotterTableModel at the implemented method. But the break point was never reached.

Regards,
pp_dv.
pp_dv
 
Posts: 5
Joined: Thu Nov 06, 2008 6:26 am

Re: Setting tooltip for headers of a table.

Postby JIDE Support » Fri Nov 07, 2008 9:54 am

We actually find the nested table model that implements ToolTipSupport and use it. Could you please make a simple test case for it and post here?

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37263
Joined: Sun Sep 14, 2003 10:49 am

Re: Setting tooltip for headers of a table.

Postby Walter Laan » Mon Nov 10, 2008 1:44 am

Reading this thread I tought lets add header tooltips to our program, but I got the same problem.
It happens when a new table header is set or createDefaultTableHeader() is overridden.

Add the following code to SortableTableDemo:
Code: Select all
_sortableTable = new SortableTable(new SortableTableModel(tableModel)) {
  @Override
  protected JTableHeader createDefaultTableHeader() {
    return new SortableTableHeader(getColumnModel());
  }
};

// or only the to following line also shows the problem
// _sortableTable.setTableHeader(new SortableTableHeader(_sortableTable.getColumnModel()));


So if you could add a protected method installTableHeaderTooltips(), we could call that when overriding the createDefaultTableHeader method and you can call it in setTableHeader().
Walter Laan
 
Posts: 383
Joined: Mon May 01, 2006 12:13 am

Re: Setting tooltip for headers of a table.

Postby pp_dv » Mon Nov 10, 2008 6:36 am

Hello,

Thanks for all your replies. I have found a workaround for this issue. I had added a mouse listener and mouse motion listener to the table header. These listeners do the job of displaying the tooltip. It seems to be working fine.

Thanks again.

pp_dv
pp_dv
 
Posts: 5
Joined: Thu Nov 06, 2008 6:26 am

Re: Setting tooltip for headers of a table.

Postby JIDE Support » Mon Nov 10, 2008 11:36 am

The table header has to know how to retrieve the tooltip. Here is our code in JideTable.

Code: Select all
    @Override
    protected JTableHeader createDefaultTableHeader() {
        if (isNestedTableHeader()) {
            return new NestedSortableTableHeader(getColumnModel()) {
                @Override
                public String getToolTipText(MouseEvent event) {
                    String toolTipText = getTableHeaderToolTipText(event);
                    if (toolTipText != null) {
                        return toolTipText;
                    }
                    else {
                        return super.getToolTipText(event);
                    }
                }
            };
        }
        else {
            return new SortableTableHeader(getColumnModel()) {
                @Override
                public String getToolTipText(MouseEvent event) {
                    String toolTipText = getTableHeaderToolTipText(event);
                    if (toolTipText != null) {
                        return toolTipText;
                    }
                    else {
                        return super.getToolTipText(event);
                    }
                }
            };
        }
    }
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37263
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 9 guests