本文整理汇总了Java中javafx.scene.control.ListView.setEditable方法的典型用法代码示例。如果您正苦于以下问题:Java ListView.setEditable方法的具体用法?Java ListView.setEditable怎么用?Java ListView.setEditable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.ListView
的用法示例。
在下文中一共展示了ListView.setEditable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ComboBoxListViewSample
import javafx.scene.control.ListView; //导入方法依赖的package包/类
public ComboBoxListViewSample() {
ListView<Object> listView = new ListView<>();
listView.getItems().addAll(items);
listView.setEditable(true);
listView.setCellFactory(ComboBoxListCell.forListView(items));
getChildren().add(listView);
}
示例2: TextFieldListViewSample
import javafx.scene.control.ListView; //导入方法依赖的package包/类
public TextFieldListViewSample() {
final ListView<String> listView = new ListView<String>();
listView.setItems(FXCollections.observableArrayList("Row 1", "Row 2", "Long Row 3", "Row 4", "Row 5", "Row 6", "Row 7",
"Row 8", "Row 9", "Row 10", "Row 11", "Row 12", "Row 13", "Row 14", "Row 15", "Row 16", "Row 17", "Row 18",
"Row 19", "Row 20"));
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
listView.setEditable(true);
listView.setCellFactory(TextFieldListCell.forListView());
getChildren().add(listView);
}
示例3: ChoiceBoxListViewSample
import javafx.scene.control.ListView; //导入方法依赖的package包/类
public ChoiceBoxListViewSample() {
ListView<Object> listView = new ListView<>();
listView.getItems().addAll(items);
listView.setEditable(true);
listView.setCellFactory(ChoiceBoxListCell.forListView(items));
getChildren().addAll(listView, new Button("Click me"));
}
示例4: StringListInput
import javafx.scene.control.ListView; //导入方法依赖的package包/类
/**
* String List input constructor
*
* @param parameterValues List with all parameters
* @param index Index of the parameter that the input should use.
* @param defaultValue Default value for the list. Expected to be in the form "[string1, string2]" etc.
*/
public StringListInput(List<JPair<String, Object>> parameterValues, int index, String defaultValue) {
// Create HashSet instance and add it to the parameters
set = new HashSet<>();
parameterValues.get(index).setRight(set);
// Create the editable list
ObservableList<String> stringList = FXCollections.observableArrayList();
ListView<String> simpleList = new ListView<>(stringList);
simpleList.setEditable(true);
simpleList.setCellFactory(TextFieldListCell.forListView());
simpleList.setOnEditCommit(t -> simpleList.getItems().set(t.getIndex(), t.getNewValue()));
// Create the add/remove item buttons
Button addBtn = new Button("Add");
addBtn.onActionProperty().setValue(event -> stringList.add("(double click to edit)"));
Button removeBtn = new Button("Remove last");
removeBtn.onActionProperty().setValue(event -> {
ObservableList<String> list = simpleList.getItems();
// Only try to remove if list contains at least 1 item
if (list.size() > 0) {
list.remove(list.size() - 1);
}
});
HBox addRemoveHBox = new HBox();
addRemoveHBox.setSpacing(5);
addRemoveHBox.setAlignment(Pos.CENTER);
addRemoveHBox.getChildren().add(addBtn);
addRemoveHBox.getChildren().add(removeBtn);
// Add a listener to the string list, so when it changes we update the Set
simpleList.getItems().addListener((ListChangeListener<String>) c -> {
// Clear the current set's contents, and add the new ones
set.clear();
set.addAll(simpleList.getItems());
});
// Add buttons to the container
this.setSpacing(5);
this.getChildren().add(simpleList);
this.getChildren().add(addRemoveHBox);
// If there is a default value for the list, add it now
if (!defaultValue.equals("-")) {
// Remove first and last characters (which are expected to be square brackets)
defaultValue = defaultValue.substring(1, defaultValue.length() - 1);
// Split into Strings and add them to the set
String[] strings = defaultValue.split(", ");
// Update the list with the new strings (which also updates the HashSet because of the listener)
simpleList.getItems().addAll(strings);
}
}