### Tooltip Set Style

To change the tooltip style, an option is to make use of a CSS file.
Example Changing Tooltip Style using B4J Visual Designer
Create an external CSS file
Create in the Project Files Folder a CSS file (like Main.css) with content:
.tooltip {
-fx-background-radius: 2 2 2 2;
-fx-background-color: linear-gradient(#FFFFFF, #DEDEDE);
-fx-text-fill: black;
-fx-font-size: 20px;
}
In B4J code set the MainForm style - this style applies to all controls:
MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "Main.css"))
Compile and Test
Compile the B4J project in the IDE (F5) and test the tooltip.
Notes
• The CSS File has to be added to every Form used for the project (if same styling should be used)
• The CSS File can also include other settings beyond the Tooltip styling
Another example of changing the tooltip style of a button using API methods (Requires the JavaObject library).
This can be applied to other views as well - change Button to another view.
Usage
Button_SetToolTipStyle(Button1, "-fx-font-size:20;-fx-background-color: linear-gradient(#FFFFFF, #DEDEDE); -fx-text-fill: orange;")
Button_SetToolTipStyle(Button2, "-fx-font-size:20;-fx-text-fill: yellow;")
Subroutine
`Private Sub Button_SetToolTipStyle(Btn As Button, Style As String)
Dim joButton As JavaObject = Btn
Dim ToolTipText As String = Btn.TooltipText
Dim joToolTip As JavaObject
joToolTip.InitializeNewInstance("javafx.scene.control.Tooltip", Array(ToolTipText))
joToolTip.RunMethod("setStyle", Array(Style))
joButton.RunMethod("setTooltip", Array(joToolTip))
End Sub`
Advanced Example
Set the tooltip style for buttons in a form, if the button tag is 1.
`Private Sub Form_SetButtonsTooltipStyle(frm As Form)
For Each n As Node In frm.RootPane.GetAllViewsRecursive
If n Is Button And n.Tag = "1" Then
Button_SetToolTipStyle(n, "-fx-font-size:20;-fx-background-color: linear-gradient(#FFFFFF, #DEDEDE); -fx-text-fill: black;")
End If
Next
End Sub`

Changed: 2018-05-01 17:34, Category: Application, File: T6C159M1189.htm, ID: 1189