java - why onMouseClick doesnt work in javafx circle shape? -




i want click on 1 of 3 button on title of internal window change color black. times works , does`nt work. please @ code tell me whats wrong it!?

i used javac 1.8u20 compile , jre 1.9 run... if use or 3 layer of pane inside of each other how events handle? there problem?

package core.windowmanager;  import javafx.geometry.insets; import javafx.geometry.pos; import javafx.scene.cursor; import javafx.scene.node; import javafx.scene.control.label; import javafx.scene.effect.dropshadow; import javafx.scene.layout.*; import javafx.scene.paint.color; import javafx.scene.shape.circle; import javafx.stage.screen;  import static javafx.scene.paint.color.rgb;  /**  * created yn on 22/08/17.  * declare win not more ...  */ public class win {  /**  * add win in scene  */ private final anchorpane root; /**  * title , hashcode instance  win id  */ private final string winid; /**  * win pane contains title , content pane  */ private final anchorpane winpane = new anchorpane(); /**  * title pane add title label , 3 [close-min-max] buttons maybe...  */ private final anchorpane titlepane = new anchorpane(); /**  * content goes there ...  */ private final anchorpane content = new anchorpane();  /**  * win title pane height  */ private final int wintitlepaneh = 30; /**  * 3 close-min-max buttons  */ private final circle closeshape = new circle(); private final circle minshape = new circle(); private final circle maxshape = new circle();   /**  * initialize win class important params  *  * @param root  //where win add scene  * @param title // , string id make title+hashcode , used in windowmanager  * @param winw  //win width  * @param winh  // win height  */ public win(anchorpane root, string title, int winw, int winh) {      //init final vars     this.root = root;     this.winid = title + "--" + this.hashcode();      // make winpane     winpane.seteffect(new dropshadow(20, rgb(0, 0, 0, 0.9)));     winpane.setprefsize(winw, winh);     winpane.setstyle("-fx-background-color: #abcdef");     // put winpane center of scene     double screenw = screen.getprimary().getvisualbounds().getwidth();     double screenh = screen.getprimary().getvisualbounds().getheight();     double deltaw = (screenw - winw) / 2;     double deltah = (screenh - winh) / 2;     winpane.setlayoutx(deltaw);     winpane.setlayouty(deltah);     // put top on click     winpane.setonmouseclicked(e -> {         winpane.tofront();     });      //make title , top of window ...     titlepane.setprefheight(wintitlepaneh);     anchorpane.settopanchor(titlepane, 0.0);     anchorpane.setleftanchor(titlepane, 0.0);     anchorpane.setrightanchor(titlepane, 0.0);      // make winpane draggable titlepane     makedragable(titlepane);     makeresizable(50);      // add close , min buttons title pane     closeshape.setradius(wintitlepaneh / 3);     closeshape.setfill(color.red); //red-yellow-green     closeshape.setonmouseclicked(e -> {         closeshape.setfill(color.black);         e.consume();     });      //add min button title pane     minshape.setradius(wintitlepaneh / 3);     minshape.setfill(color.yellow); //red-yellow-green     minshape.setonmouseclicked(e -> {         minshape.setfill(color.black);     });      // add max button title pane     maxshape.setradius(wintitlepaneh / 3);     maxshape.setfill(color.green); //red-yellow-green     maxshape.setonmouseclicked(e -> {         maxshape.setfill(color.black);      });      hbox bb = new hbox();     //bb.setbackground(new background(new backgroundfill(color.black, null, insets.empty)));     anchorpane.setleftanchor(bb, 0d);     anchorpane.settopanchor(bb, wintitlepaneh / 4.5);     anchorpane.setbottomanchor(bb, 0d);     bb.getchildren().addall(closeshape, minshape, maxshape);     titlepane.getchildren().addall(bb);       // add label show title     label titlel = new label(title);     titlel.settextfill(color.black);     titlel.setalignment(pos.baseline_center);     anchorpane.settopanchor(titlel, 5.0);     anchorpane.setleftanchor(titlel, 0.0);     anchorpane.setrightanchor(titlel, 0.0);     titlepane.getchildren().add(titlel);       titlepane.setbackground(new background(new backgroundfill(color.web("#e2e0e2"), cornerradii.empty, insets.empty)));      winpane.getchildren().add(titlepane);     root.getchildren().add(winpane);   }   /**  * titlepane drag , win move behavior  *  * @param  */ public void makedragable(node what) {     final delta dragdelta = new delta();      what.setonmousepressed(mouseevent -> {         dragdelta.x = winpane.getlayoutx() - mouseevent.getscreenx();         dragdelta.y = winpane.getlayouty() - mouseevent.getscreeny();         //also bring front when moving         winpane.tofront();      });      what.setonmousedragged(mouseevent -> {         winpane.setlayoutx(mouseevent.getscreenx() + dragdelta.x);         winpane.setlayouty(mouseevent.getscreeny() + dragdelta.y);      }); }  //current state private boolean resize_bottom; private boolean resize_right;  public void makeresizable(double mouseborderwidth) {     winpane.setonmousemoved(mouseevent -> {         //local window's coordiantes         double mousex = mouseevent.getx();         double mousey = mouseevent.gety();         //window size         double width = winpane.boundsinlocalproperty().get().getwidth();         double height = winpane.boundsinlocalproperty().get().getheight();         //if on edge, change state , cursor         if (math.abs(mousex - width) < mouseborderwidth                 && math.abs(mousey - height) < mouseborderwidth) {             resize_right = true;             resize_bottom = true;             winpane.setcursor(cursor.nw_resize);         } else {             resize_bottom = false;             resize_right = false;             winpane.setcursor(cursor.default);         }      });     winpane.setonmousedragged(mouseevent -> {         //resize root         region region = (region) winpane;         //resize logic depends on state         if (resize_bottom && resize_right) {             region.setprefsize(mouseevent.getx(), mouseevent.gety());         } else if (resize_right) {             region.setprefwidth(mouseevent.getx());         } else if (resize_bottom) {             region.setprefheight(mouseevent.gety());         }     }); }  //just encapsulation private static class delta {     double x, y; } 

}

mouse click works fine on circle in javafx. problem code label add title on top of circles , catches mouse clicks. can click circles on bottom made think works "sometimes". check image here:

inspected scenicview

so can solve making label mouse transparent with:

titlel.setmousetransparent(true); 

or adding first label , hbox circles.

for kind of problems scenicview comes handy tool.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -