Search code examples
javahtmlstylesjavafxtooltip

Tooltip using html javafx


I want to add a tooltip on a checkbox of javafx. I want to make it using java code. This tooltip text depends on some object properties. My problem is that i want to have some(not all) words bold inside the tooltip. Is there any way to do it? As far as i googled i didn't found a solution or a way to do it using for example html. It would be a charm if i could do something like this:

PaggingTest paggingTest = new PaggingTest();
Tooltip tooltip = new Tooltip(
    "<b>AlgorithmType:</b> " + paggingTest.getAlgorithmType()
    + "<br/><b>Memory Pages:</b> " + paggingTest.getMemoryPages()
    + "<br/><b>Program Pages:</b> " + paggingTest.getProgramPages()
    + "<br/><b>Sample Count:</b> " + paggingTest.getSampleCount()
    + "<br/><b>Distribution Type:</b> " + paggingTest.getDistributionType());

CheckBox checkBox = new CheckBox("Test");
checkBox.setTooltip(tooltip);
testFlowPane.getChildren().add(checkBox);

Solution

  • You could try this:

    WebView  web = new WebView();
    WebEngine webEngine = web.getEngine();
    webEngine.loadContent
    (
        "<b>AlgorithmType:</b> " + paggingTest.getAlgorithmType()
        + "<br/><b>Memory Pages:</b> " + paggingTest.getMemoryPages()
        + "<br/><b>Program Pages:</b> " + paggingTest.getProgramPages()
        + "<br/><b>Sample Count:</b> " + paggingTest.getSampleCount()
        + "<br/><b>Distribution Type:</b> " + paggingTest.getDistributionType()
    );
    
    Tooltip  tip = new Tooltip();
    tip.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    tip.setGraphic(web);
    

    You may have to apply some css styling to the webview to get it to blend in with your tip.