Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JMenu Problem  RSS feed

 
R hello
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Im having trouble with a a JMenu poping up in the following program, first off, I can sort of see the JMenu because very little box shows up that you can barely see. Also when add a blank component to the north parth of the content pane I can see the menu. There are 2 custom JPanels, one that lets the user choose a color, one that displays a square with the color selected from the user. Anyways im trying to figure out how to get the JMenu to appear without adding a blank component to the content pane.

Applet/JFrame with JMenu




ColorChooser Custom JPanel


Custom JPanel to display selected color


Thanks in advance for the help.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing/AWT...
 
R hello
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh.. sorry I saw the Swing section on the forums after I posted and wondered if this post was gonna get moved.
Sorry, thanks for moving post.
 
Brian Cole
Author
Ranch Hand
Posts: 932
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JApplet extends java.awt.Applet extends java.awt.Panel,
and therefore your JApplet is heavyweight. So even though
your JMenuItem is on top (in the sense of Z-order) of your
JApplet, the JApplet will actually appear on top of the
JMenuItem. See this for details on why.

So what to do? Probably simplest is to just use heavyweight AWT
MenuBar/Menu/MenuItem instead of Swing JMenuBar/JMenu/JMenuItem.

You also could make MyColorChooserTest extend JPanel instead of
JApplet, but that's a little more work.

PS. You can omit the fileMenu.setPopupMenuVisible(true) line.
[ October 26, 2005: Message edited by: Brian Cole ]
 
R hello
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks, Brian, both those solutions worked perfectly.
And thanks for pointing out that I left that setPopupMenuVisible() in there, hehe, I was trying random things to figure out how to fix it before I just gave up.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!