Skip to main content

JMenuBar does not close menu

3 replies [Last post]
casc84
Offline
Joined: 2010-10-19

Hi all, I have a problem and I hope you'll help me...

I make a JMenuBar and it works fine but...when I open a menu, it doesn't close if I click out of it.

Do any of you have had this problem?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
walterln
Offline
Joined: 2007-04-17

No. Post a short sample program showing the problem if you want further help (use [ code ] code here [ /code ] tags without the spaces when posting code.

casc84
Offline
Joined: 2010-10-19

Ok, here is the code:

[code]
public GestorHerramientasAplicacion(JFrame ventanaPadre) {
this.ventanaPadre = (JFrame)ventanaPadre;
mapaBotones = new HashMap();
mapaMenus = new HashMap();
mapaItemsMenu = new HashMap();
mapaEventos = new HashMap();

barraMenu = new JMenuBar();
barraBotones = new JToolBar();
barraBotones.setFloatable(false);

try {
configuracionInicial();
} catch (Exception e) {
e.printStackTrace();
}
}

protected JMenu creaMenu(String etiqueta) {
JMenu menu = new JMenu(etiqueta);
mapaMenus.put(etiqueta, menu);
return menu;
}

public void configuracionInicial() {
mapaEventos.clear();
mapaItemsMenu.clear();
mapaMenus.clear();
mapaBotones.clear();

JMenuItem menuItem;
JMenu menu;

//Menu File
menu = creaMenu("Archivo");
menu.setMnemonic('A');

menuItem = creaMenuItem(NUEVO, EventoAplicacion.EV_BT_NUEVO);
menuItem.setIcon(new ImageIcon(CtesConsola.tomaIcono(8)));
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
ActionEvent.CTRL_MASK));
menu.add(menuItem);

menuItem = creaMenuItem(GRABAR, EventoAplicacion.EV_BT_GRABAR);
menuItem.setIcon(new ImageIcon(CtesConsola.tomaIcono(9)));
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,
ActionEvent.CTRL_MASK));
menu.add(menuItem);

menuItem = creaMenuItem(CONGELAR, EventoAplicacion.EV_BT_CONGELAR);
menuItem.setIcon(new ImageIcon(CtesConsola.tomaIcono(27)));
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
ActionEvent.CTRL_MASK));
menu.add(menuItem);

menuItem = creaMenuItem(BORRAR, EventoAplicacion.EV_BT_BORRAR);
menuItem.setIcon(new ImageIcon(CtesConsola.tomaIcono(22)));
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,
ActionEvent.CTRL_MASK));
menu.add(menuItem);

menuItem = creaMenuItem(SALIR, EventoAplicacion.EV_BT_SALIR);
menuItem.setIcon(new ImageIcon(CtesConsola.tomaIcono(0)));
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,
ActionEvent.ALT_MASK));
menu.add(menuItem);

barraMenu.add(menu);
}
[/code]

darrylburke
Offline
Joined: 2010-08-05

Can't compile the code, hence can't run the code ... recommended reading:
http://mindprod.com/jgloss/sscce.html

db