java - how to getChildname from a vbox -
this question has answer here:
i need filename of imageview within vbox upon pressing button?? here file arraylist has been added vbox, vbox gridpane possible using vbox.getchildren()?? or else how should proceed. here's screenshot better understanding:

here's code:
private arraylist<button> btnar; private vbox vb; private button downloadbtn; @fxml private scrollpane displayscroll; private gridpane gridpane; public homeui_2controller() { platform.runlater(new runnable() { @override public void run() { gridpane = new gridpane(); displayscroll.setcontent(gridpane); btnar = new arraylist<>(); (int = 0; < filelist2.size(); i++) { downloadbtn = new button("download"); btnar.add(downloadbtn); } int imagecol = 0; int imagerow = 0; (int = 0; < filelist2.size(); i++) { system.out.println(filelist2.get(i).getname()); image = new image(filelist2.get(i).touri().tostring()); pic = new imageview(); pic.setfitwidth(130); pic.setfitheight(130); pic.setimage(image); vb = new vbox(); vb.getchildren().addall(pic, (button) btnar.get(i)); gridpane.add(vb, imagecol, imagerow); gridpane.setmargin(pic, new insets(2, 2, 2, 2)); imagecol++; // check if 3 images of row completed if (imagecol > 2) { // reset column imagecol = 0; // next row imagerow++; } } **downloadbtn.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent arg0) { system.out.println("sssss"); system.out.println( vb.getchildren().contains(pic.getid())); } });** } }); }
this code unclear, , i'm not sure understand you're doing here. (is controller? if so, why initializing ui in platform.runlater(), inside constructor, instead of in standard initialize() method? why of ui components apparently defined in fxml, , others defined in java code in controller? hard follow.)
but, seems have list called filelist2 (you don't show declaration) i'm guessing contains filenames. create list of buttons of same size. i'm guessing idea add action event handler each button corresponding element of filelist2 list.
in order can add event handler each button inside first for loop:
(int = 0; < filelist2.size(); i++) { downloadbtn = new button("download"); btnar.add(downloadbtn); final int index = ; downloadbtn.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent event) { // filelist2.get(index); // ... } }); }
Comments
Post a Comment