Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 610
Georgios Syngouroglou Avatar asked Jan 27 '26 23:01

Georgios Syngouroglou


1 Answers

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.

like image 198
Jurgen Avatar answered Jan 30 '26 11:01

Jurgen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!