B4J Code Snippet Consistent Tooltips

Something which has been bugging me recently and finally got round to looking at it. I think the tooltip inherits it's font settings from the control. They can look very inconsistent if using FontAwesome or Material Icons.





So to make them consistent:
B4X:
Sub SetToolTipFont(N As Control,F As Font)
    Dim JoN As JavaObject = N
    JoN.RunMethodJO("getTooltip",Null).RunMethod("setFont",Array (F))
End Sub





To call:

SetToolTipFont(BtnExcel,fx.CreateFont("Arial",16,True,False))
SetToolTipFont(CboSheet,fx.CreateFont("Arial",16,True,False))
SetToolTipFont(BtnTemplate,fx.CreateFont("Arial",16,True,False))
 

walt61

Active Member
Licensed User
Longtime User
Nice one, @keirS, thanks! That bugged me too but I hadn't given it any further thought (and might not have found a solution anyway); I've added some code to apply it across a form:

B4X:
Sub SetAllToolTipFonts(frm As Form, F As Font) As Int

    Dim numDone As Int = 0

    For Each n As Node In frm.RootPane.GetAllViewsRecursive
        Try
            If SetToolTipFont(n, F) Then numDone = numDone + 1
        Catch
            Log("SetAllToolTipFonts: " & LastException)
        End Try
    Next

    Return numDone

End Sub

Sub SetToolTipFont(N As Control, F As Font) As Boolean

    Try
        Dim JoN As JavaObject = N
        JoN.RunMethodJO("getTooltip",Null).RunMethod("setFont",Array (F))
        Return True
    Catch
        Return False
    End Try

End Sub
 

jmon

Well-Known Member
Licensed User
Longtime User
Note that you can also do that in CSS:
B4X:
.tooltip {
    -fx-show-delay: 150ms;
    -fx-show-duration: 5000ms;
    -fx-hide-delay: 200ms;
    -fx-background-radius: 2 2 2 2;
    -fx-background-color: green;
    -fx-text-fill: white;
    -fx-font-size: 25px;
    -fx-font-family: 'monospace';
    -fx-font-style: oblique;
}
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…