This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMenu + JPanel Problem

 
Gordon Freeman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic