本文整理汇总了Java中javafx.scene.control.ListView.setPrefWidth方法的典型用法代码示例。如果您正苦于以下问题:Java ListView.setPrefWidth方法的具体用法?Java ListView.setPrefWidth怎么用?Java ListView.setPrefWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.ListView
的用法示例。
在下文中一共展示了ListView.setPrefWidth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: list
import javafx.scene.control.ListView; //导入方法依赖的package包/类
private ListView<String> list() {
ListView<String> tables = new ListView<>(FXCollections.observableArrayList());
tables.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
tables.setPrefHeight(480);
tables.setPrefWidth(256);
return tables;
}
示例2: init
import javafx.scene.control.ListView; //导入方法依赖的package包/类
private void init() {
getChildren().add(new Label("Input directories:"));
ListView<Path> list = new ListView<>(FXCollections.observableList(paths));
getChildren().add(list);
list.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
list.setPrefWidth(320);
list.setPrefHeight(200);
VBox.setVgrow(list, Priority.ALWAYS);
HBox footer = new HBox(GuiConstants.padding);
getChildren().add(footer);
footer.setAlignment(Pos.CENTER_RIGHT);
Button button = new Button("add");
footer.getChildren().add(button);
button.setOnAction(event -> {
Path path = Gui.requestDir("Select directory to add", window);
if (path != null && !list.getItems().contains(path)) list.getItems().add(path);
});
Button removeButton = new Button("remove");
footer.getChildren().add(removeButton);
removeButton.setOnAction(event -> {
Set<Path> selected = new HashSet<>(list.getSelectionModel().getSelectedItems());
list.getItems().removeIf(selected::contains);
});
ListChangeListener<Path> itemChangeListener = change -> {
okButton.setDisable(paths.isEmpty());
};
list.getItems().addListener(itemChangeListener);
ListChangeListener<Path> selectChangeListener = change -> {
List<Integer> selectedIndices = list.getSelectionModel().getSelectedIndices();
boolean empty = selectedIndices.isEmpty();
removeButton.setDisable(empty);
};
list.getSelectionModel().getSelectedItems().addListener(selectChangeListener);
itemChangeListener.onChanged(null);
selectChangeListener.onChanged(null);
}