1

I'm new to Javafx and have been trying to set the font for tooltip for a Button, I wrote the following code but the font size of the tooltip seems to be the same irrespective of the font size I give

Button button = new Button("Button");
Tooltip tooltip = new Tooltip("My name is the Ghost");
tooltip.setFont(new Font(15));
button.setTooltip(tooltip);

I have tried with new Font(15.0) and new Font(15d) , but no luck.

I can however change the font style, by writing,

 tooltip.setFont(new Font("Arial", 15));

But the font size remains same,

However

tooltip.setStyle("-fx-font-size: 15");

Seems to work,

Here is the full code

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class ToolTipTester extends Application {

public static void main(final String[] args) {
launch(args);
}


@Override
public void start(final Stage primaryStage) {
  Group root = new Group();

  primaryStage.setScene(new Scene(root, 500, 500));

  Button button = new Button("Button");
  root.getChildren().add(button);

  Tooltip tooltip = new Tooltip("My name is the Ghost");
  tooltip.setFont(new Font(15));

  button.setTooltip(tooltip);
  primaryStage.show();

  }
}

Why doesnt the first method work? What am I doing wrong?

I'm using Javafx8 with Java8

Thanks in advance!

Courage
  • 772
  • 8
  • 20

0 Answers0