Re: setToolTips in a JTable
- From: IchBin <weconsul@xxxxxxx>
- Date: Mon, 29 Aug 2005 09:41:24 -0400
Elmar Brauch wrote:
Hello,
I have a JTable and I want to give every tableheader a diffrent tooltip.
But I don't know, how I get the tableheaders for using the setToolTip-method.
Can anyone help me?
Regards, Elmar
The following code implements the tool tips. Basically, it creates a subclass of JTableHeader that overrides the getToolTipText(MouseEvent) method so that it returns the text for the current column. To associate the revised table header with the table, the JTable method createDefaultTableHeader is overridden so that it returns an instance of the JTableHeader subclass.
protected String[] columnToolTips = {
null,
null,
"The person's favorite sport to participate in",
"The number of years the person has played the sport",
"If checked, the person eats no meat"};
... JTable table = new JTable(new MyTableModel()) {
... //Implement table header tool tips.
protected JTableHeader createDefaultTableHeader() {
return new JTableHeader(columnModel) {
public String getToolTipText(MouseEvent e) {
String tip = null;
java.awt.Point p = e.getPoint();
int index = columnModel.getColumnIndexAtX(p.x);
int realIndex =
columnModel.getColumn(index).getModelIndex();
return columnToolTips[realIndex];
}
};
}
}
See http://java.sun.com/docs/books/tutorial/uiswing/components/table.html --
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-) .
- References:
- setToolTips in a JTable
- From: Elmar Brauch
- setToolTips in a JTable
- Prev by Date: Eclipse Plugin - Export: class not found
- Next by Date: Re: What to override inJComboBox
- Previous by thread: Re: setToolTips in a JTable
- Next by thread: What to override inJComboBox
- Index(es):