java - JavaFX Dynamically Adding Elements to a GridPane -
i'm relatively new javafx , i've been pretty confused in why code below not produce intended result being label added grid.
what i'm trying run test adding javafx label fxml gridpane construct method in near-future allow user choose file, generate label when user has selected file , add label gridpane.
thanks in advance,
code:
private label label1; @fxml private gridpane gridpane; @fxml public void handle() { filechooser filechooser = new filechooser(); filechooser.settitle("select file"); filechooser.getextensionfilters().addall( new filechooser.extensionfilter("video files", "*.mp4", "*.avi"), new filechooser.extensionfilter("audio files", "*.wav", "*.mp3", "*.aac"), new filechooser.extensionfilter("all files", "*.*")); //show open file dialog file file = filechooser.showopendialog(null); try { system.out.println(file.getpath()); system.out.println(file.getname()); label1.settext(file.getname()); gridpane.add(label1, 1, 1); } catch (exception e) { } }
the fxml code standard file defined gridpane fx:id listed above.
you don't initialize label anywhere, null. since you're squashing exception, don't see nullpointerexception that's generated when call label1.settext(...)
Comments
Post a Comment