Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JMenuItem is not visible, why?  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a JApplet with JMenu, but when it is pulled down, the JMenuItem is not visible, part of which is hidden by the component below.
I have a Canvas added in a JPanel than add JPanel in the center of JApplet, then I find the canvas hides the JMenuItem, but when I tried with Swing class instead of Canvas, it's OK.
How can I use AWT class like Canvas, but not hide the JMenuItem?
Thanks a lot!
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi wonda,
If u try to mix swing and awt components u r expected to get unpredictable results.
the reason is that u can't mix lightweight(swing) components with heavyweight components(awt).
and I don't think there is any way to mix them without getting unexpected o/p.
regards
deekasha

 
Pandora Odum
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The heavyweight (awt)components will always hide your lightweight components (swing). If you feel you must have the canvas instead of a JPanel or JLabel, you will have to move your canvas to another area so that it does not hide your menu items.
 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can force your menu to be heavyweight by using the following statement:
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
This will cause the menu always to be painted over anything else.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"wonda",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.
Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!