Results 1 to 3 of 3
  1. #1
    doron70 is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default problem in setMnemonic for JMenu in JApplet

    Hi,

    I'm using this chunk of code below.
    setMnemonic works fine for JMenuItem but not for JMenu
    (although it does show the underline under the letter G
    it gives nothing when I press ALT G)

    I'm using Java 1.5_0_16

    Thanks


    // Game menu
    gameMenu = new JMenu( "Game");
    gameMenu.setMnemonic(KeyEvent.VK_G);
    // New Item
    newItem = new JMenuItem( "New");
    newItem.setMnemonic(KeyEvent.VK_N);

    gameMenu.add( newItem);

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

  3. #3
    doron70 is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default

    I do exactly what it is written.. see code below.
    I get the same problem with JMenu.
    Maybe it's because I use JApplet and not JFrame?



    import javax.swing.JApplet;

    import java.awt.*;

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

    import java.applet.*;

    public class menuFrame extends JApplet
    {
    public menuFrame()
    {
    JMenuBar menuBar;
    JMenu menu;
    JMenuItem menuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescripti on(
    "The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item",
    KeyEvent.VK_T);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescr iption(
    "This doesn't really do anything");
    menu.add(menuItem);

    setJMenuBar(menuBar);

    }

    }

Similar Threads

  1. JMenu on Right side problem
    By justbeller in forum AWT / Swing
    Replies: 2
    Last Post: 03-05-2011, 05:11 PM
  2. problem with jmenu,please help!!!
    By beni.vd in forum AWT / Swing
    Replies: 4
    Last Post: 12-31-2010, 07:08 PM
  3. problem with jframe&jmenu&graphics
    By beni.vd in forum AWT / Swing
    Replies: 1
    Last Post: 12-31-2010, 07:07 PM
  4. setMnemonic
    By newbie123 in forum Java Software
    Replies: 1
    Last Post: 04-20-2010, 05:05 PM
  5. Applet in JFrame, JMenu problem
    By Bill86 in forum New To Java
    Replies: 5
    Last Post: 12-28-2009, 04:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •