2 JMenu Questions

Go To StackoverFlow.com

-3

I know this might be a little "basic" but I've looked at every tutorial possible, and they don't tell me.

So Question 1:

I am trying to put a link in the JMenuBar, how about would I go on doing that?

Question 2:

When I try to add something to a menu bar, it doesn't add it.

I have all of my imports right and I get 0 errors, so why is it not letting me?

Code:

        JFrame frame = new JFrame();    

    JMenuBar mb = new JMenuBar();
    frame.setJMenuBar(mb);

    JMenu file = new JMenu("File");
    mb.add(file);
2012-04-04 19:52
by John M
This adds a JMenu "File" to your JMenuBar. What are you expecting it to do - ControlAltDel 2012-04-04 19:56
What kind of a link do you want in your JMenuBar - ControlAltDel 2012-04-04 19:57
@user1291492 Like a link to go to different sites, such as google or whatnot - John M 2012-04-04 20:06
1) For better help sooner, post an SSCCE. 2) It is best to limit questions to ..one question per question - Andrew Thompson 2012-04-05 01:41


2

Actually you can add JMenuItem to JMenuBar. I don't think you can add a file on JMenuBar. And you can listener on JMenuItem and link to wherever you want.

2012-04-04 19:57
by mbaydar


2

If you want to click on a menu item to open a link in a web browser, first create a method that will do this - browse() a URL in your browser, test it from your main method, then you can create JMenuItems and set an Action that will call your method

2012-04-04 20:18
by ControlAltDel
Ads