如果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();
}
}
但如果添加一个样式,则显示样式:
ObservableList<String> items = FXCollections.observableArrayList("First item");