JavaFx-执行框架到组合框

时间:2019-06-02 21:32:51

标签: java javafx

我有组合框,需要为其创建框架。如何添加下面的框架?

comboBox frame

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");

1 个答案:

答案 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也可以更简单。