我有组合框,需要为其创建框架。如何添加下面的框架?
ComboBox<String> combobox = new ComboBox<String>();
ObservableList<String> items = FXCollections.observableArrayList("RED", "BLUE", "GREEN", "YELLOW", "BLACK");
combobox.setItems(items);
combobox.setTranslateX(250);
combobox.setTranslateY(300);
combobox.setPromptText("Circle Color");
答案 0 :(得分:0)
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("BorderPane Test");
//Creating StackPane
StackPane sp = new StackPane();
// add Combobox to scene
ComboBox<String> combobox = new ComboBox<String>();
ObservableList<String> items = FXCollections.observableArrayList("RED", "BLUE", "GREEN", "YELLOW", "BLACK");
combobox.setItems(items);
combobox.setTranslateX(250);
combobox.setTranslateY(300);
combobox.setPromptText("Circle Color");
sp.getChildren().add(btn);
//Adding StackPane to the scene
Scene scene = new Scene(sp,300,200);
primaryStage.setScene(scene);
primaryStage.show();
}
}
在外部CSS文件中设置组合框的样式。互联网上有许多教程如何做到这一点。例如,查看here。甚至不需要额外的文件here也可以更简单。