• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JMenu + JPanel Problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic