To reproduce run following code
1 test case: choose some item in choice box, press "reset" button. Choice box become shoter.
2 test case: try to add some long item "looooooooooo00000ong" . Choice box doesn't change the size.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ChoiceBoxSa extends Application {
ChoiceBox cb;
protected Scene getScene() {
cb = new ChoiceBox();
HBox content = new HBox(5);
content.getChildren().add(cb);
reset();
HBox addBox = new HBox();
final TextField toAdd = new TextField();
Button addBtn = new Button("Add");
addBtn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
cb.getItems().add(toAdd.getText());
}
});
HBox clearBox = new HBox();
Button resetBtn = new Button("Reset");
resetBtn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
reset();
}
});
clearBox.getChildren().add(resetBtn);
addBox.getChildren().add(toAdd);
addBox.getChildren().add(addBtn);
VBox controls = new VBox();
controls.getChildren().add(clearBox);
controls.getChildren().add(addBox);
content.getChildren().add(controls);
Scene res = new Scene(content);
return res;
}
protected void reset() {
cb.getItems().clear();
cb.getItems().add("1234567890");
cb.getItems().add(3);
cb.getItems().add(false);
}
public static void main(String args[]) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
stage.setScene(getScene());
stage.show();
}
}
1 test case: choose some item in choice box, press "reset" button. Choice box become shoter.
2 test case: try to add some long item "looooooooooo00000ong" . Choice box doesn't change the size.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ChoiceBoxSa extends Application {
ChoiceBox cb;
protected Scene getScene() {
cb = new ChoiceBox();
HBox content = new HBox(5);
content.getChildren().add(cb);
reset();
HBox addBox = new HBox();
final TextField toAdd = new TextField();
Button addBtn = new Button("Add");
addBtn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
cb.getItems().add(toAdd.getText());
}
});
HBox clearBox = new HBox();
Button resetBtn = new Button("Reset");
resetBtn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
reset();
}
});
clearBox.getChildren().add(resetBtn);
addBox.getChildren().add(toAdd);
addBox.getChildren().add(addBtn);
VBox controls = new VBox();
controls.getChildren().add(clearBox);
controls.getChildren().add(addBox);
content.getChildren().add(controls);
Scene res = new Scene(content);
return res;
}
protected void reset() {
cb.getItems().clear();
cb.getItems().add("1234567890");
cb.getItems().add(3);
cb.getItems().add(false);
}
public static void main(String args[]) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
stage.setScene(getScene());
stage.show();
}
}