import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.Separator;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBoxBuilder;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class CheckBoxEllipsis extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
final double INITIAL_WIDTH = 150.;
final double MAX_WIDTH = 450.;
VBox vb = new VBox(10d);
final CheckBox cb = new CheckBox();
cb.setMaxWidth(INITIAL_WIDTH);
String testString = "01234567890qazwsxedcrfvtgbyhnujmikolp";
String ellipsis = "WWW";
cb.setText(testString);
cb.setEllipsisString(ellipsis);
cb.setStyle("-fx-border-color:blue");
vb.getChildren().addAll(cb, new Separator());
final TextField tfEllipsis = new TextField();
Button btnSetEllipsis = new Button("Set ellipsis string");
btnSetEllipsis.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
cb.setEllipsisString(tfEllipsis.getText());
}
});
vb.getChildren().add(HBoxBuilder.create().children(tfEllipsis, btnSetEllipsis).build());
final Label lblCurWidth = new Label("" + INITIAL_WIDTH);
vb.getChildren().add(lblCurWidth);
ScrollBar scrollBar = new ScrollBar();
scrollBar.setMin(0);
scrollBar.setValue(INITIAL_WIDTH);
scrollBar.setMax(MAX_WIDTH);
scrollBar.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
cb.setMaxWidth(t1.doubleValue());
lblCurWidth.setText("" + t1.doubleValue());
}
});
vb.getChildren().add(scrollBar);
Scene scene = new Scene(vb, 400, 300);
stage.setScene(scene);
stage.setTitle(System.getProperty("java.runtime.version") + "; " + System.getProperty("javafx.runtime.version"));
stage.show();
}
}