osx - How can I implement Java/Swing controls that are disabled until after the window is activated? -
i implementing java/swing application macos, common mouse button related behavior disabled until window activated. in other words, when mouse button pressed on inactive window, window activated nothing else happens. (there exceptions. buttons when clicked activate window , run normal action.) there way this? basic problem time application gets mouse pressed event, window active. thought far correlate window activated event , mouse pressed event time, might not reliable.
you can make button's contains() depends on frame's active or not:
final jframe frame = new jframe(); jbutton button = new jbutton() { @override public boolean contains(int x, int y) { return super.contains(x, y) && frame.isactive(); } };
when frame deactive , region of button clicked, button won't accept mouse event since contains() returns false, button's parent tested contains() instead (and parent's parent until returns true), still makes frame active, button not given chance response mouse click.
Comments
Post a Comment