• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic