Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Incorrect position of a popup menu

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My app is displying a popup menu on a right-click but
1) if the frame is at the bottom of the screen then it is shown outside the screen.
2) if there is another window right below my app, the popup is displayed under the other window ..
That's very user-friendly ...
Can someone help ?
Thx
P-
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pascal,
I don't understand your second question.
For the first question, try this
(1) Calculete your Jpopupmenu size
JPopupMenu popup = new JPopupMenu();
Dimension popupSize = popup.getPreferredSize();
(2) Calculate your screen size
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
(3) Get your mouse position by passing mouseEvent me
int showX = me.getX();
int showY = me.getY();
(4) Turn up or turn left
if (me.getY() + popupSize.height > screenSize.height)
showY = me.getY() - popupSize.height;
if (me.getX() + popupSize.width > screenSize.width)
showX = me.getX() - popupSize.width;
popup.show(me.getComponent(), showX, showY);
Help it helps and good luck.
Renee
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic