Re: JPopupMenu positioning
- From: Sabine Dinis Blochberger <no.spam@xxxxxxxxxxxx>
- Date: Wed, 23 Jan 2008 12:47:56 GMT
Thomas Fritsch wrote:
Sabine Dinis Blochberger schrieb:
[...]
I've reproduced your problem. In the debugger I saw:
When the method is called for the first time, jPopupMenu1.getWidth()
returns 0, because the popup (a package-private member variable in
JPopupMenu) is not yet realized.
When it is called the for second/third/... time, jPopupMenu1.getWidth()
returns 20, and all is fine.
That is a great insight!
I have tried figuring out the location for the menu after the call to
show (using setLocation()), but was having problem determining the Point
(on screen, or in relation to the frame). I suspect SwingUtilities might
help with the conversion of coordinate spaces.
Yes, that is what I will put inplace now, until I get more time toI would take a pragmatic route, and decide to display the popup menu
I also tried to set the popup menus on screen location directly, but
never found out how to get the correct point. This might be a possible
solution, to call jPopupMenu1.setLocation().
*left*-aligned, instead of *right*-aligned to the button:
private void jButton1ActionPerformed(java.awt.event.ActionEvent
evt) {
// show the popupmenu
jPopupMenu1.show(jButton1, 0, jButton1.getHeight());
}
I know this is not quite what wanted, but at least it behaves consistently.
fiddle, which is probably never <g>.
Thank you very much for your time, Thomas.
--
Sabine Dinis Blochberger
Op3racional
www.op3racional.eu
.
- References:
- JPopupMenu positioning
- From: Sabine Dinis Blochberger
- Re: JPopupMenu positioning
- From: Thomas Fritsch
- JPopupMenu positioning
- Prev by Date: Re: JPopupMenu positioning
- Next by Date: Events
- Previous by thread: Re: JPopupMenu positioning
- Next by thread: Opportunity to Work!- Mail me back
- Index(es):