• Post Reply Bookmark Topic Watch Topic
  • New Topic

what if i dont like where mouse gets clicked  RSS feed

 
Jigar Gosar
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yellow,
i have written many programs which involve non rectangular components and these components overlap each other.
For each of these components i have registered mousemotion and mouse listeners but now when mouse gets clicked in the region of the component which is not the valid region for my non rectangular-component the eventhandler for it still gets called.
What i want is that somehow to re fire the event for all the components which are below this component(when the mouse event is fired in the invalid region of the component) so that components below get a fair chance.
your help will be appreciated.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to AWT.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is the method:
SwingUtilities.getDeepestComponentAt(comp, x, y);
Maybe that would do what you want.
Chantal
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you'll have to attach the listener to the container that contains all your components and have the container propegate events to the components inside it. Since generic java components are rectangular, but yours aren't, you could get the rectangular bounds of the components using the getBounds() methods to determine what components you should propegate events to, but in the methods in the components make sure the propegated events are within your non-rectangular bounds.
 
Jigar Gosar
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first thanks for replying.
to Chantal Ackermann
your suggestion will give me only the deepest component. but i want the component excatly below the component where my mouse has clicked. and i want this only to happen if mouse has clicked on the invalid region of component who recived the event
to Nathan Pruett
your suggestion is great but it had alredy occured to me. the problem with it is that it is very tiresome when u have to write the code for event dispaching every time for all events viz. clicked , pressed, released, dragged, moved........etc.I would prefer a solution in which after my component has recived an event and has determined for itself that the event is invalid it could fire the same event to component (if any)below it.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, the component itself has no idea of the component below it... only the component's container does...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!