### Toolbar Add Hyperlink Button

Example of adding a Hyperlink button to the Top-Toolbar of the HTML Editor.
Requires the libraries jReflection and JavaObject.
The button uses the icon link-add.png which is stored in the project files folder.
Add the Button at AppStart
`Sub AppStart (Form1 As Form, Args() As String)
...
' Use callsubdelayed to add the button to the right of the top-toolbar
CallSubDelayed(Me, "AddHyperlinkButton")
...
Sub to add the Hyperlink Button
`Sub AddHyperlinkButton
Dim joHE As JavaObject = HTMLEditor1
Dim joTB As JavaObject = joHE.RunMethod("lookup", Array(".top-toolbar"))
Dim btnHL As Button
btnHL.Initialize("btnHL")
btnHL.Text = "Hyperlink"
btnHL.PrefHeight = 26
btnHL.PrefWidth = 26
AddButtonIcon(btnHL, "link-add.png")
joTB.RunMethodJO("getItems", Null).RunMethod("add", Array(btnHL))
End Sub`
`Sub AddButtonIcon(btn As Button, icon As String)
CSSUtils.SetStyleProperty(btn, "-fx-background-position","center")
CSSUtils.SetStyleProperty(btn, "-fx-background-repeat", "no-repeat")
Dim iconpath As String = File.GetUri(File.DirAssets, icon)
CSSUtils.SetStyleProperty(btn, "-fx-background-image", $"url('${iconpath}');"$)
' Do not set the backgroundcolor to transparent
'CSSUtils.SetStyleProperty(btn, "-fx-background-color", "transparent")
End Sub`
`Sub btnHL_Action
Dim url As String = $""MySite""$
Dim jo As JavaObject = HTMLEditor1
Dim r As Reflector
r.Target = jo.RunMethodJO("getSkin", Null)
jo = r.GetField("webView")
jo.RunMethod("requestFocus", Null)
jo = jo.RunMethod("getEngine", Null)
jo.RunMethod("executeScript", Array("document.body.focus()"))
jo.RunMethod("executeScript", Array($"var range, node;
if (window.getSelection && window.getSelection().getRangeAt) {
window.getSelection().deleteFromDocument();
range = window.getSelection().getRangeAt(0);
node = range.createContextualFragment(${url});
range.insertNode(node);
} else if (document.selection && document.selection.createRange) {
document.selection.createRange().pasteHTML(${url});
document.selection.clear();
}"$))
End Sub`
`

Changed: 2018-06-07 09:13, Category: HTMLEditor, File: T6C198M1458.htm, ID: 1458