-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
8
-
Java 1.8.0ea b83
I am attempting to constrain the size of tooltips as a precaution in my application. I have found that using setMaxWidth works well when used with the wrap text property to flow large tooltips. Unfortunately when wrap text is true the tooltip uses max width but ignores max height.
If you run the below test case you will see that the tooltip is not square as it should be. I did test and if your text has manual line breaks and wrap text is false then the tooltip does honor max height and the text is truncated as it should be.
**********************************
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class TooltipTest extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
String text = "Lorem ipsum dolor sit amet, consectetur adipiscing " +
"elit. Nulla consequat, odio quis ultrices egestas, risus nisi " +
"consequat sapien, id tincidunt arcu nisl vitae metus. Sed velit " +
"velit, consectetur eu fringilla id, tempor imperdiet sem. Sed " +
"urna tortor, sollicitudin non ultricies eu, bibendum at sem. " +
"Nam justo massa, porta bibendum interdum commodo, iaculis non " +
"est. Aenean ornare bibendum nulla, at ultricies ante convallis " +
"non. Phasellus ac est eget libero pharetra gravida. Vestibulum " +
"a felis dolor. Quisque vel sodales nisi. Aliquam consequat " +
"porttitor metus in facilisis. Aliquam a porta lectus. Praesent " +
"ornare nisl sed purus tempus nec dignissim tortor tincidunt.";
primaryStage.setWidth(600);
primaryStage.setHeight(400);
primaryStage.centerOnScreen();
Circle c = new Circle(100);
c.setFill(Color.DODGERBLUE);
final Tooltip tooltip = new Tooltip();
tooltip.setText(text);
tooltip.setWrapText(true);
tooltip.setMaxWidth(250);
tooltip.setMaxHeight(250);
Tooltip.install(c, tooltip);
StackPane spane = new StackPane( c );
spane.setPadding(new Insets(50));
primaryStage.setScene( new Scene(spane) );
primaryStage.show();
}
public static void main(String[] args) throws Exception{
launch(args);
}
}
If you run the below test case you will see that the tooltip is not square as it should be. I did test and if your text has manual line breaks and wrap text is false then the tooltip does honor max height and the text is truncated as it should be.
**********************************
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class TooltipTest extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
String text = "Lorem ipsum dolor sit amet, consectetur adipiscing " +
"elit. Nulla consequat, odio quis ultrices egestas, risus nisi " +
"consequat sapien, id tincidunt arcu nisl vitae metus. Sed velit " +
"velit, consectetur eu fringilla id, tempor imperdiet sem. Sed " +
"urna tortor, sollicitudin non ultricies eu, bibendum at sem. " +
"Nam justo massa, porta bibendum interdum commodo, iaculis non " +
"est. Aenean ornare bibendum nulla, at ultricies ante convallis " +
"non. Phasellus ac est eget libero pharetra gravida. Vestibulum " +
"a felis dolor. Quisque vel sodales nisi. Aliquam consequat " +
"porttitor metus in facilisis. Aliquam a porta lectus. Praesent " +
"ornare nisl sed purus tempus nec dignissim tortor tincidunt.";
primaryStage.setWidth(600);
primaryStage.setHeight(400);
primaryStage.centerOnScreen();
Circle c = new Circle(100);
c.setFill(Color.DODGERBLUE);
final Tooltip tooltip = new Tooltip();
tooltip.setText(text);
tooltip.setWrapText(true);
tooltip.setMaxWidth(250);
tooltip.setMaxHeight(250);
Tooltip.install(c, tooltip);
StackPane spane = new StackPane( c );
spane.setPadding(new Insets(50));
primaryStage.setScene( new Scene(spane) );
primaryStage.show();
}
public static void main(String[] args) throws Exception{
launch(args);
}
}