in javafx have pane , inside pane smaller pane mouse listener. want detect mouse entered if mouse pressed. how?? ... smaller pane detect mouse entered not if mouse pressed elsewhere on parent pane , entered smaller pane.
here i've written problem in code, though have problem in project, problem same, can use solusion. problem!
import javafx.application.application; import javafx.event.eventhandler; import javafx.scene.scene; import javafx.scene.control.label; import javafx.scene.input.mouseevent; import javafx.scene.layout.flowpane; import javafx.scene.layout.pane; import javafx.stage.stage; public class mousetest extends application { public void start(stage primarysstage) throws exception { primarysstage.settitle("problem"); pane wrapper = new flowpane(); wrapper.setprefsize(400, 400); wrapper.setstyle("-fx-background-color: #ffffff"); scene scene = new scene(wrapper, 400, 400); primarysstage.setscene(scene); pane innerpane = new pane(); innerpane.setprefsize(200, 200); innerpane.setstyle("-fx-background-color: green"); eventhandler<mouseevent> mouseentered = new eventhandler<mouseevent>() { @override public void handle(mouseevent e) { innerpane.setstyle("-fx-background-color: black"); } }; eventhandler<mouseevent> mouseexited = new eventhandler<mouseevent>() { @override public void handle(mouseevent e) { innerpane.setstyle("-fx-background-color:green"); } }; innerpane.setonmouseentered(mouseentered); innerpane.setonmouseexited(mouseexited); wrapper.getchildren().add(innerpane); label lb = new label("\n\n\n\t\t\t\t+\n\npress mouse here , enter green pane:\n not detect!" + " want detect mouse entered \nregardless of mouse pressed or not! how?"); wrapper.getchildren().add(lb); primarysstage.show(); } public static void main(string[] args) { launch(args); } }
in imitation saying don't bring them fish, instead teach them how fish, let me show trick.
use
scene.addeventfilter(mouseevent.any, e -> system.out.println( e));
to detect mouse events , show them in console. obvious event catch , solve future problems regarding mouse events. or event if use event.any
.
Comments
Post a Comment