B4J Code Snippet TableView: Adding tooltips to column headers

Discussion in 'B4J Code Snippets' started by Mashiane, Aug 20, 2018.

  1. Mashiane

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

    Code:
    '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... ;)
     
    amaxco, inakigarm, Erel and 2 others like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice