この記事では、Javafxの[My Computer Explorer]の簡単な実装について説明します。あなたの参照のために全員のためにそれを共有してください。詳細は次のとおりです。
1。Javaコード:
パッケージttt; Import java.io.file; Import javafx.application.Application; Import javafx.beans.value.changelistener; Import javafx.beans.value.obser vableValue; Import javafx.collections.fxCollections; Import Javafx.Collections.observablelist; javafx.scene.scene; Import javafx.scene.control.tablecolumn; Import javafx.scene.control.tableview; Import javafx.scene.control.treeitem; Import ort javafx.scene.layout.borderpane; Import javafx.cene.layout .hbox; Import javafx.scene.layout.priority; Import javafx.stage.stage; import javafx.scene.control.treeview; Import javafx.scene.control.cell.proper tyvalueFactory; public class treeviews拡張アプリケーション{Public Static Ombablerist <<<< filedetail> data = fxcollections.observablearraylist(); Resource Management "); treeitem <file> rootitem = new treeitem <>(new file.getenv(" Computername ")))); ; gethildren()。 Tablecolumn <filedetail> firstcolumn = new tablecolumn <>( "file"); SecondColumn = new tablecolumn <>( "Type"); (「最後の修正」); setcellvalueFactory(wiledetail>( "lastmodified"); SethGrow(Tree、Priority.always.SeethGrow.GetChildren(); <file >>(){@override public void chander(ObservableValue <?extends treeitem <file >> Observable、TreeItem <file> OldValue、TreeItem <file> newValue){Observable list <treeitem <file >> treeList = newValue.getChildren (); observablelist = fxcollections.observablearraylist(); Setall(TableList);
2。Javaコード:
パッケージ; java.text.simpledateformat; public class filedetail {privename lastmodified;文字列型。 fileName.getName(); .length = file.length(); if(isfolder){type = "folder} G etfileName(){filename} setfileName(filename = filename} {return type} settype(this.type =} {relong length){
3。Javaコード:
パッケージTTT; java.io.file;インポートjavafx.collections.fxcollections; Impont javafx.collections.observablelist; public class filetreitem extends treeitem <file> True; setall(これ)} ISFILE(); ISLEAFを返します} private observablerist <file >> buildChildren [] files = f.listfiles(); if(files!= null){treeitem <file >> fxcollections.observablearraylist() );
4。ランニング効果のスクリーンショット:
この記事がすべての人のJavaプログラムのデザインに役立つことが期待されています。