B4J Code Snippet TableView: Adding tooltips to column headers


Licensed User

This is no magic really, some time ago there was a post here about adding fontawesome buttons to headers, so I included it on my snippets, here too.

I have realized something, my table has abbreviations and I sometimes forget what they even mean. Lol.


So me things, there is already a button added, why not also include a tooltip. The tableView setGraphic method comes handy to do that, however it does not extend the column width. So I had to read the column width and then increase it by the button icon width..

'set an icon for a column header
Sub TableViewSetColumnHeaderToolTip(idxPos As int, Tooltip As String)
    If idxPos = -1 Then Return
    Dim cWidth As Double = TV.GetColumnWidth(idxPos)
    Dim btn As Button
    btn.PrefWidth = 32
    btn.PrefHeight = 32
    btn.Enabled = True
    btn.MouseCursor = fx.Cursors.HAND
    btn.Font = awesome
    btn.Text = Chr(0xF128)
    btn.TooltipText = Tooltip
    CSSUtils.SetBackgroundColor(btn, fx.Colors.Transparent)
    'expand the with
    TV.SetColumnWidth(idxPos,cWidth + 32)
End Sub

'set the column graphic
private Sub TableViewSetColumnGraphicOnly(Index As Int, xNode As Node)
    Dim jo As JavaObject = TV
    Dim column As JavaObject = jo.RunMethodJO("getColumns", Null).RunMethod("get", Array(Index))
    column.RunMethod("setGraphic", Array(xNode))
End Sub
So now, even if I forget, I can just hover on the Q mark and know what the column is about... ;)