Re: [Java-gnome-developer] ButtonPressEvent not working ...
Brought to you by:
afcowie
From: Andrew C. <an...@op...> - 2009-09-23 22:21:49
|
On Wed, 2009-09-23 at 08:37 -0400, Thura wrote: > But, when it runs, the context menu doesn't show up ... > I have tried replacing ButtonPressEvent with KeyPressEvent, it > works ... You've been bitten by the well known beginner's pitfall "my example is so trivial that not everything that would be present in a real application is there, so things that would normally work fine appear not to be working at all" In this case, you've not got enough packed into your top level Window to make it behave. In fact, you haven't got _anything_ packed into your top level Container. So, really, it's not that surprising that not everything is working. Quick solution: Pack an EventBox into your top level Window and connect your Widget.ButtonPressEvent handler to that instead. I tried it, works fine. Underlying issue: Ordinarily you don't have to think about this as normal GTK Widgets take care of this, but your problem was that the underlying GDK Window backing the GTK Window hasn't been setup to react to mouse events. There are a few branches floating around with different suggestions about how to offer direct access to that API, but you don't need any of that; just add an EventBox - it's there to give Widgets that don't have event handling (ie, Labels) events. AfC Sydney |