清单ListView没有外观样式

时间:2016-12-26 16:00:22

标签: java javafx-2

如果ListView为空,则它不会显示样式等:

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.stage.Stage;

public class ListViewExample extends Application {
      @Override
      public void start(Stage primaryStage) throws Exception {
        ListView<String> list = new ListView<String>();
        ObservableList<String> items = FXCollections.observableArrayList();
        list.setItems(items);
        Group group = new Group();
        group.getChildren().add(list);
        Scene scene = new Scene(group, 500, 500);
        primaryStage.setScene(scene);
        primaryStage.show();
      }
}

enter image description here

但如果添加一个样式,则显示样式:

ObservableList<String> items = FXCollections.observableArrayList("First item");

enter image description here

是否有内置选项(不添加空项),例如: enter image description here

0 个答案:

没有答案