亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Gluon JavaFX 中是否有任何文件導航?

Gluon JavaFX 中是否有任何文件導航?

慕妹3242003 2023-06-04 14:52:08
假設您要使用使用 Gluon JavaFX 創建的應用程序打開圖片或文件。是否有任何文件導航窗口可用于選擇該文件或圖片?假設我們知道我們的localRoot = /rootFile localRoot = Services.get(StorageService.class)             .flatMap(s -> s.getPublicStorage(""))             .orElseThrow(() -> new RuntimeException("Error retrieving private storage"));或者我是否需要手動將文件放在文件夾中,然后使用表格視圖掃描所有文件并將它們放在表格視圖中以便我可以選擇它們?
查看完整描述

1 回答

?
慕容3067478

TA貢獻1773條經驗 獲得超3個贊

您對公共存儲 API 的使用是錯誤的,您需要提供一個有效的名稱,例如Documents或Pictures。這些是文件系統中的有效公用文件夾。


例如,您可以獲得此類文件夾中的文件列表:


File picRoot = Services.get(StorageService.class)

            .flatMap(s -> s.getPublicStorage("Pictures"))

            .orElseThrow(() -> new RuntimeException("Folder notavailable")); 


File[] files = picRoot.listFiles();    

if (files != null) {

    for (File file : files) {

        System.out.println("File: " + file);

    }

}

您如何處理這些文件,或者如何將這些文件呈現給用戶,都取決于您。


但是,如果您想瀏覽圖像庫,并將這些圖像呈現給用戶,以便他/她可以選擇一個,您應該使用PicturesService::loadImageFromGallery:


從設備的圖像庫中檢索圖像


這將使用本機瀏覽器應用程序,您可以搜索所有帶有圖片的常用文件夾。


它將返回一個Optional<Image>(如果用戶取消則為空),您還可以使用getImageFile()返回Optional<File>與原始圖像關聯的文件。


來自 JavaDoc:


ImageView imageView = new ImageView();

Services.get(PicturesService.class).ifPresent(service -> {

    // once selected, the image is visualized

    service.loadFromGallery().ifPresent(image -> imageView.setImage(image));

    // and the file can be shared

    service.getImageFile().ifPresent(file -> 

      Services.get(ShareService.class).ifPresent(share -> 

          share.share("image/jpeg", file)));

 });


查看完整回答
反對 回復 2023-06-04
  • 1 回答
  • 0 關注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號