Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes JMenu + JPanel Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JMenu + JPanel Problem" Watch "JMenu + JPanel Problem" New topic
Author

JMenu + JPanel Problem

Gordon Freeman
Greenhorn

Joined: Jul 19, 2005
Posts: 1
OK, i know it might be a little strange what I'm trying to do but none the less I have to do it. So here is my problem:
I neeed to add a JPanel, containing several components, as a JMenuItem to a JMenu, and have it behave normally(allowing me to select options, check/uncheck boxes and any other similar activities).
I managed to get it to show up, but the form that apears in the JMenu is uselles. All components from inside the JPannel do not react the way they should. It's like the events are't even passed . Here is the code I have so far (any help is MOSTLY appreciated):

import java.awt.*;
import javax.swing.*;

public class Post {


static GridBagConstraints constraints = new GridBagConstraints();
static JFrame frame = new JFrame("Advanced Menu");
JPanel aditionalPane = new JPanel(new GridBagLayout());;
JCheckBox jco;
JCheckBox jct;

private JPanel advancedOpts(){

constraints.gridx = 0;
constraints.gridy = 0;
jco = new JCheckBox("JCheck One", true);
aditionalPane.add(jco,constraints);

constraints.gridy = 1;
jct = new JCheckBox("Jcheck Two", true);
aditionalPane.add(jct,constraints);

return this.aditionalPane;
}

private JMenuBar advAsMenu(){

JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Advanced Menu");
JMenuItem item = new JMenuItem();
menu.add(item.add(advancedOpts()));
menuBar.add(menu);

return menuBar;
}

public static void main(String[] args) {

Post am = new Post();

frame.setMaximumSize(new Dimension(500,500));
frame.setMinimumSize(new Dimension(500,500));
frame.setPreferredSize(new Dimension(500,500));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(am.advAsMenu());
frame.pack( );
frame.setVisible(true);
}
}

Thank you all in advance for all your time and support.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMenu + JPanel Problem
 
Similar Threads
toolbar in internalframe
JMenu Update
JFrame and JMenu
Gridbag Layout
How to disable Menubar