B4J Code Snippet Consistent Tooltips

Discussion in 'B4J Code Snippets' started by keirS, Dec 15, 2018.

  1. keirS

    keirS Well-Known Member Licensed User

    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.

    [​IMG]
    [​IMG]
    [​IMG]

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

    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))
     
    jmon, BPak, Erel and 3 others like this.
  2. walt61

    walt61 Active Member Licensed 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:

    Code:
    Sub SetAllToolTipFonts(frm As Form, F As FontAs 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 FontAs Boolean

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

    End Sub
     
  3. jmon

    jmon Well-Known Member Licensed User

    Note that you can also do that in CSS:
    Code:
    .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;
    }
     
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