B4J Code Snippet TableView: Adding tooltips to column headers

Mashiane

Expert
Licensed User
Ola

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.

ToolTip.png


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..

B4X:
'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.Initialize("")
    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)
    CSSUtils.SetBorder(btn,0,fx.colors.transparent,0)
    TableViewSetColumnGraphicOnly(idxPos,btn)
    '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... ;)
 
Top