本文整理匯總了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);
}
}