Adding shortcuts to JFrame

I have menus in a JFrame. Each JMenuItem lunches differents JInternalFrame. I want the JFrame to lunch MenuItem Action while using Function Keys like F1 etc.
I used setMnemonic()... but doesn't work. I used JFrame implements KeyListener but, Dunno why, work sometimes. What I have to do?
Thanks a lot

How to Use Menus:
http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html
I used setMnemonic()... You should be using an accelerator.

Similar Messages

  • Adding JApplet to JFrame

    Hi
    we can add an applet in JFrame(if it takes no parameters) e.g.
    jFrameObject.getContentPane( ).add(anAppletObject);
    but if an applet takes some parameters for initialization, then how i can pass parameters to that applet. means what is the code for passing parameters to an applet.
    Thanks in Advance
    Yahya Kamran

    Well the key to your problem is an interface called "AppletStub".
    What you need to do is define a own Class which implements AppletStub.
    Therefore define methods to retrieve parameters or a constructor doing that and the one to get the parameters in your custom AppletStub.
    The other methods must be implemented, too, but you can leave them blank, too. (eg. void foo() {} the empty braces are what makes the method implemented ;-) ).
    Now do follwing:
    // Creating the Applet you want to
    SillyApplet anAppletObject  = new SillyApplet();
    // Add it as you did
    jFrameObject.getContentPane().add(anAppletObject);
    // Now creating the parameters. This can be done how you like
    // (maybe an ArrayList maybe something more sophisticated)
    String[]  parameterList = new String[3];
    parameterList[0] = "one parameter";
    parameterList[1] = "another parameter" ;
    parameterList[2]  = "something special";
    parameterList[3] = "the last thing ever";
    // Assume your custom stub accepts a String[] of parameters int it's constructor
    // This is how to create such a mean Stub thing
    WeirdStub stub  = new WeirdStub(parameterList);
    // Handing the stub over to the applet
    anAppletObject.setStub(stub);
    // Now let the Applet get loose!
    anAppletObject.init();
    anAppletObject.start();Please note thus the Applet is added to the JFrame, you are still taklking to the same mean object!
    This is called reference semantics, since the variable actualy represents a pointer to the Object you are talking about.
    Another note this has to work a kind like that since the applet viewer is a java programm it self and various ide offer such a thing, too and are of course written in java, too.
    When stuck report in again.
    Greetings to your feetings,
    .o0|LIQID|0o.
    Found it in the java api source code.

  • Adding shortcut on Leopard (F keys)

    Hi, I upgraded my Mac to Leopard today, and when I tried adding F16 as my shortcut key to bring Adium to front via the preference pane, it keeps giving me an error that F16 is an universal shortcut. I checked and rechecked the keyboard prefpane, but I couldn't see a F16 anywhere.
    I've also tried all the keys from F1 to F16. No luck.
    When I was in Tiger, I used F16 as my shortcut, so it has become a habit for me. Is this a bug in the software, or did I configure something wrong??
    Thanks

    Most functions can be mapped to any keystroke combination using System Preferences > Keyboard & Mouse > Keyboard shortcuts tab.

  • Adding Shortcuts to network drives

    Is it possible in 10.5 to make a shortcut to a shared drive on networked pc or mac?

    Yes. Open it in Finder, then drag the icon under the Devices section on the left.
    If you want it to automatically load, you can add it to your Login Items (under Sys Prefs > Accounts).

  • Adding JTree to JFrame using SpringLayout

    I have created a JTree with various nodes and leafs. I want to place the JTree in a GUI that uses SpringLayout as the layout manager. What should I use to place the JTree in the JFrame? I assume I put it in a JScrollPane which serves as a container. Then how do I assign a layout manager to JScrollPane and register it with the JFrame? Does this make sense?

    Twupack, my apologies. I was not receiving any responses in the other forum so I decided to take my questions to the beginner form which is probably more suitable given the complexity of my question. I also asked a different question - regarding the same topic. And my login, although different, was not intentional. This forum asked me to enter a different login name so I did. If I really wanted to hide my identity, I think I could have figured out something a little more creative.
    Now, mods, if you could, remove this thread as I am not receiving any useful responses here.

  • Adding wallpaper to jframe

    hi,
    does anyone know how to set the background of a jframe to a wallpaper?
    thanks.

    Check out this thread:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=316074

  • Adding video in jframe?

    help please.. how can i add a video in a jframe? is it possible?

    how? i cant understand it. plesae teach me........T_TYou can do this. You just need JMF. Check out this code
    import javax.swing.*;
    import javax.media.*;
    import java.net.*;
    import java.io.*;
    public class JMFVideo1
         public static void main(String args[]) throws Exception
              Player player;
              JFrame jframe=new JFrame();
              jframe.setSize(300,300);
              JPanel jpanel=new JPanel();
              jpanel.setLayout(new BoxLayout(jpanel,BoxLayout.Y_AXIS));
              player=Manager.createRealizedPlayer(new MediaLocator(new File("G:/java files1/jmf/love.mpg").toURL()));
              player.setMediaTime(new Time(30.0));
              jpanel.add(player.getVisualComponent());
              Control controls[]=player.getControls();
              CachingControl cc=null;
              for(int i=0;i<controls.length;i++)
                   if(controls[i] instanceof CachingControl)
                        cc=(CachingControl) controls;
                        jpanel.add(cc.getProgressBarComponent());     
                        System.out.println("Found CachingControl");
              if(player.getControlPanelComponent()==null)
                   System.out.println("Null");
              else
                   jpanel.add(player.getControlPanelComponent());
              jframe.setContentPane(jpanel);
              jframe.setVisible(true);
              player.start();

  • Adding and showing jframe

    hi friends
    i add my project 10 jframe and one of them is my parents frame
    when user click to button1 jframe1 open after click to button2 then jframe1 close and jframe2 open.
    these buttons are in parent form. please help me for this situation.
    thanks everyone.

    [http://catb.org/~esr/faqs/smart-questions.html]
    To get better help sooner, post a SSCCE that clearly demonstrates the problem.
    To post code, use the code tags -- [code]Your Code[/code]will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
    db

  • How can I add a word to my autocorrect dictionary without adding shortcuts?

    Hey guys is it possible to add words to my autocorrrect dictionary without having to go to settings-keyboard and add a shortcut? Thats what I'm doing right now, but is not an ideal solution, I would like to add the word by just typing it , isn't there a way to just  "save it to the dictionary" after typing the word?

    Type the word in any app (e.g., Messages) followed by a spacebar and let it be "corrected."  Then type a backspace and other options including your original "wrong" spelling will appear above the autocorrected word. Tap the one that matches your original typing. That will change it back to the way you entered it and also adds it to the dictionary.

  • Adding a JPanel from one class to another Class (which extends JFrame)

    Hi everyone,
    So hopefully I go about this right, and I can figure out what I'm doing wrong here. As an exercise, I'm trying to write a Tic-Tac-Toe (TTT) game. However, in the end it will be adaptable for different variations of TTT, so it's broken up some. I have a TTTGame.java, and TTTSquareFrame.java, and some others that aren't relavent.
    So, TTTGame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              addPanel = startSimple();
              if(!addPanel.isValid())
                   System.out.println("Something's wrong");
              contents.add(addPanel);
              setSize(300, 300);
              setVisible(true);
         public JPanel startSimple()
              mainSquare = new TTTSquareFrame(sides);
              mainSquarePanel = mainSquare.createPanel(sides);
              return mainSquarePanel;
    }and TTTSquareFrame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.Misc;
    public class TTTSquareFrame
         private JPanel squarePanel;
         private JButton [] squares;
         private int square, index;
         public TTTSquareFrame()
              System.out.println("Use a constructor that passes an integer specifying the size of the square please.");
              System.exit(0);
         public TTTSquareFrame(int size)
         public JPanel createPanel(int size)
              square = (int)Math.pow(size, 2);
              squarePanel = new JPanel();
              squarePanel.setLayout(new GridLayout(3,3));
              squares = new JButton[square];
              System.out.println(MIN_SIZE.toString());
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setRolloverEnabled(false);
                   squares[i].addActionListener(bh);
                   //squares[i].setMinimumSize(MIN_SIZE);
                   squares[i].setVisible(true);
                   squarePanel.add(squares[i]);
              squarePanel.setSize(100, 100);
              squarePanel.setVisible(true);
              return squarePanel;
    }I've successfully added panels to JFrame within the same class, and this is the first time I'm modularizing the code this way. The issue is that the frame comes up blank, and I get the message "Something's wrong" and it says the addPanel is invalid. Originally, the panel creation was in the constructor for TTTSquareFrame, and I just added the mainSquare (from TTTGame class) to the content pane, when that didn't work, I tried going about it this way. Not exactly sure why I wouldn't be able to add the panel from another class, any help is greatly appreciated.
    I did try and cut out code that wasn't needed, if it's still too much let me know and I can try and whittle it down more. Thanks.

    Yea, sorry 'bout that, I just cut out the parts of the files that weren't relevant but forgot to compile it just to make sure I hadn't left any remnants of what I had removed. For whatever it's worth, I have no idea what changed, but something did and it is working now. Thanks for your help, maybe next time I'll post an actual question that doesn't somehow magically solve itself.
    EDIT: Actually, sorry, I've got the panel working now, but it's tiny. I've set the minimum size, and I've set the size of the panel, so...why won't it respond to that? It almost looks like it's being compressed into the top of the panel, but I'm not sure why.
    I've compressed the code into:
    TTTGame.java:
    import java.awt.*;
    import javax.swing.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              mainSquare = new TTTSquareFrame(sides.intValue());
              contents.add(mainSquare);
              setSize(400, 400);
              setVisible(true);
    }TTTSquareFrame.java
    import java.awt.*;
    import javax.swing.*;
    public class TTTSquareFrame extends JPanel
         private JButton [] squares;
         private int square, index;
         private final Dimension testSize = new Dimension(50, 50);
         public TTTSquareFrame(int size)
              super();
              square = (int)Math.pow(size, 2);
              super.setLayout(new GridLayout(size, size));
              squares = new JButton[square];
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setMinimumSize(testSize);
                   squares[i].setVisible(true);
                   super.add(squares[i]);
              setSize(200, 200);
              setVisible(true);
    I've made sure the buttons are smaller than the size of the panel, and the panel is smaller than the frame, so...
    Message was edited by:
    macman104

  • Adding a shortcut to a JMenuItem

    Sorry to be such a newbie, but I really cant work this out.
    I have created a JMenuBar, added several JMenuItem to it.. How do i go about adding shortcuts to these items (Like Ctrl+N for new)
    Thanks
    N

    look at:
    public void setAccelerator(KeyStroke keyStroke)

  • Multithreaded Pacman: only last animated panel added to JFrame is displaye

    Hello,
    I am making a multithreaded pacman game. Pacman and each of the ghosts run in a separate thread.
    However, only the last item (ie. pacman or one of the ghosts) added to the JFrame is displaying in the maze. (pacman and each of the ghosts are subclasses of JPanel). For example, if I do:
    add(pacman);
    add(orangeGhost);
    add(redGhost);
    only the red ghost animation will appear on the maze(which is also a subclass of JPanel).
    I have tried adding the ghosts to pacman and then adding pacman i.e. pacman.add(redGhost); add(pacman); but this still doesn't work - only pacman is showing in the maze.
    Each thread runs fine on its own, but only the last one added is displaying.
    Any help is much appreciated.

    Hi,
    JFrame uses the BoderLayout layout manager, and when you add a JPanel after the other inside your JFrame they will get put one on top of other. None of the layout manager let you overlap components with transparency as far as I know. Also your JPanels are not transparent but opaque.
    I think what you need is to "paint" your game on a JPanel o canvas, take a look at this tutorial:
    http://javaboutique.internet.com/tutorials/Java_Game_Programming/
    Keep asking around, people with more experience can help you on this forum.
    Regards,

  • Java Graphics -- Drawing Strings on JFrame

    Hello and thank you. I'm relatively young and I apologize for asking noob questions. The problem I am having is that I realized after 3 hours of research and then writing this code that when multiple JPanels are added to a JFrame, they overlap (I think) over each other. As a result, the output of this program below is at the bottom right of the frame, the number 841 appears (the last number in my array) and everything else is blank.
    And I could not at all understand how to create graphics objects. It kept giving me an error of not being able to be instantiated. And to be honest, I don't even really understand whats going on when I add the text to my JPanel. I never call paintComponents. And definately I could never even make a graphics object to provide it the parameter required. Anyway, I resolved to use Jpanels because they can be removed using the remove function of the JFrame. And It is vitally important that I can delete the strings off my frame. Here is my code:
    package main;
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    public class VisualFrame extends JFrame{
        ArrayList<JPanel> numbers = new ArrayList<JPanel>();
        public VisualFrame(){
            setSize(1000, 500);
            setTitle("Binary Search");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        public void createPanels(int[] array){
            int x = 10;
            int y = 20;
            int xOffset = 50;
            int yOffset = 50;
            for(int i=0; i<array.length; i++){
                String num = Integer.toString(array);
    numPanel panel = new numPanel(num, x, y);
    numbers.add(panel);
    add(panel);
    x = x+xOffset;
    if(x>this.getWidth()){
    x = 10;
    y = y+yOffset;
    class numPanel extends JPanel{
    String num;
    int x;
    int y;
    public numPanel(String str, int x, int y){
    num = str;
    this.x = x;
    this.y = y;
    public void paintComponent(Graphics g){
    g.setColor(Color.black);
    g.setFont(new Font("Times", Font.BOLD, 12));
    g.drawString(num, x, y);
    My main method is inside of a different class:
        public static void main(String[] args){
            VisualFrame frame = new VisualFrame();
            frame.createPanels(array);
        }Firstly, do I even have the problem I'm having right? If so,
    Is there a way to restrict the size of the panels to the length and width of what it contains?
    Or can someone give me a good, very detailed link to how to use Graphics? Or perhaps someone could prove to me a good method.
    Edited by: 989946 on Mar 8, 2013 6:45 PM

    Why don't you start by learning from the experts?
    The Java Tutorial has sections that show how to use Java functionality.
    http://docs.oracle.com/javase/tutorial/
    The Graphiics section covers GUI and Swing
    http://docs.oracle.com/javase/tutorial/uiswing/index.html
    >
    Creating Graphical User Interfaces
    Creating a GUI with Swing — A comprehensive introduction to GUI creation on the Java platform.
    >
    And that section has links for trails such as how to use ALL of the different swing components including frames and panels
    http://docs.oracle.com/javase/tutorial/uiswing/components/index.html
    >
    Using Swing Components tells you how to use each of the Swing components — buttons, tables, text components, and all the rest. It also tells you how to use borders and icons.

  • How Do You Set the Maximum Size of a JFrame?

    Can someone show me a quick example? The JFrame can be empty, I just want to know how to set it's maximum size. I tried using setMaximumSize() and it doesn't work for some reason but setMinimumSize() works fine.
    I tried it using a BoxLayout and even using null as a layout manager and can't get it to work. I heard that the other layout managers don't allow you to set the maximum size of a JFrame so that is why I tried it with the layouts that I did.
    I tried the following code (imported the necessary classes), but it does not work...
    public class MyFrame extends JFrame
        public MyFrame()
            super("TestFrame");
            setLayout( new BoxLayout(getContentPane(), BoxLayout.X_AXIS)  );       
            setMaximumSize( new Dimension(400,200));
            setSize(300,150);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible( true );                
    }// end class

    Reposted from
    {color:#0000ff}http://forum.java.sun.com/thread.jspa?threadID=5236259{color}
    @OP:
    When you repost a topic, please always provide a link to the previous post so people can check what suggestions were already offered (and didn't solve the problem).
    Better still, give a short summary of the advice you have already tried.
    I suggested setBackground(...) so you can see whether your MyFrame is actually occupying the entire real estate of the window. Looks as if trying it out (which I would have done for you if I'd been at home, where my JDK is) would have been too much effort for you.
    I'm pretty much a novice in Swing, but I can tell you this: setLayout controls the layout of components added to the JFrame, not the layout of the frame with respect to its parent container.
    Luck, Darryl

  • How to set Max size of InternalFrame should be size of JFrame?

    Hi,
    I added the toolbar on the BorderLayout North,
    JDesktopPane on the BorderLayout Center and the
    statusBar on the BorderLayout South.
    Whenever the toolbar gets clicked,the JInternalFrame is added into the JDesktopPane.
    I want like,
    If is click the maximize button of JInternalFrame, it has to maximize the size of the JFrame,and the JIF title has to added with the JFrame title,
    how to go ahead?In which Listener i have to try for maximize button for JInternalFrame?
    | Main - x |
    | TollBar |
    |----------------------- |
    || Child - x | |
    |----------------------- |
    | |
    | |
    I would like this...
    | Main - Child - x |
    | TollBar - x |
    | |
    | |
    | |
    | |
    | |
    I am waiting for suggestion from the experts.
    If any one have a idea,pls. guide me to go ahead.

    Its not supported.

Maybe you are looking for

  • Can 2 different iphones share the same apple ID?

    Can my husband who just got a I phone use my apple ID?  He wants to get our Itunes from the computer on his phone.

  • Change the name of window in SAP B1 8.8

    Dear All, I want to change the name of the A/R Down Payment request window to some other name. I have tried to do the same from frontend from document numbering but the problem is since there are no separate series for Down Payment request & invoice

  • ???????  / unessary question marks in e-mail

    Good morning: When I forward e-mails to a PC the people mget several ??? in the copy of the e-mail. Any explanation?

  • Programmatically Turn Off Printing (Acrobat 6.0)

    Hello. I'm searching (fruitlessly so far) for an option to turn off printing on a PDF. I've gone down multiple avenues and have come up empty to date. My company is using Documentum SCS and Content Transformation Services (Documentum) to export/conve

  • Splitting PST file

    Hi Team, i am having microsoft outlook 2010. my pst file size is 10 Gb. i have splitted my pst file as yearly basis. Since my pst file is too large. My question is .. even though after i splitted my current pst file. The size of the current pst file