如何从列表视图中选择多个项目

编程入门 行业动态 更新时间:2024-10-20 20:47:38
本文介绍了如何从列表视图中选择多个项目 - JavaFX 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是使用 JavaFX 的新手,我正在尝试将 ObservableList 添加到表视图中。 该列表仅包含String。

I'm new at using JavaFX and I'm trying to add an ObservableList to a table view. The list contains only String.

我的目标是显示已连接设备的列表,并让用户选择执行操作(1或更多),有没有更好的方法来实现这一目标?

My goals is to show list of connected devices and let the user choose on which to perform the action (1 or more), is there any better way to achieve this?

编辑:我已经导航到ListView,现在它显示了列表,如何从所选项目创建新列表?

Ive chaned to ListView and now it shows the list, how can I create a new list from the selected Items ?

推荐答案

以下是基于您的评论的示例

Here's an example based on your comments

import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.ListView; import javafx.scene.control.SelectionMode; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class ListSelect extends Application { @Override public void start(Stage stage) { ObservableList<String> items = FXCollections.observableArrayList( "one","two","three","four","five","six","seven"); ListView<String> list = new ListView<>(items); ListView<String> selected = new ListView<>(); HBox root = new HBox(list, selected); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); //set this to SINGLE to allow selecting just one item list.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); list.getSelectionModel().selectedItemProperty().addListener((obs,ov,nv)->{ selected.setItems(list.getSelectionModel().getSelectedItems()); }); } public static void main(String[] args) {launch(args);} }

更多推荐

如何从列表视图中选择多个项目

本文发布于:2023-11-10 22:25:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1576628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   视图   项目   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!