【问题标题】:JavaFx - do frame to combo box [duplicate]JavaFx - 对组合框做框架[重复]
【发布时间】:2019-10-18 12:29:32
【问题描述】:

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

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

【问题讨论】:

    标签: java javafx


    【解决方案1】:
    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

    【讨论】:

      猜你喜欢
      • 2014-12-25
      • 2020-04-01
      • 2019-02-27
      • 1970-01-01
      • 2014-04-08
      • 2019-08-23
      • 2017-02-08
      • 2015-03-06
      • 1970-01-01
      相关资源
      最近更新 更多