• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic