Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6129881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:47:38+00:00 2026-05-23T16:47:38+00:00

My code works correctly, except for the submenu. The Import button is supposed to

  • 0

My code works correctly, except for the submenu. The “Import” button is supposed to expand into newsfeed, bookmarks, and mail. However, the program doesn’t even display “Import”. It displays the first submenu entry (“newsfeed”) which cannot be hovered. What am I doing wrong?

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

public class test extends JFrame{

private static final long serialVersionUID = 1L;

public static void main(String[] args){
    SwingUtilities.invokeLater(new Runnable(){
        public void run(){
            test ex = new test();
            ex.setVisible(true);
        }
    });
}   

public test()
{
    initGUI();
}

public final void initGUI()
{
    JMenuBar menubar = new JMenuBar();
    ImageIcon exitIcon = new ImageIcon("icons/exit.png");
    ImageIcon openIcon = new ImageIcon("icons/open.png");
    ImageIcon newIcon = new ImageIcon("icons/new.png");
    ImageIcon saveIcon = new ImageIcon("icons/save.png");

    JMenu file = new JMenu("File");

    JMenuItem importMenu = new JMenuItem("Import");
    importMenu.setMnemonic(KeyEvent.VK_M);

    JMenuItem newsfeedMenu = new JMenuItem("Import newsfeed list...");
    JMenuItem bookmarksMenu = new JMenuItem("Import bookmarks...");
    JMenuItem mailMenu = new JMenuItem("Import mail...");

    importMenu.add(newsfeedMenu);
    importMenu.add(bookmarksMenu);
    importMenu.add(mailMenu);

    JMenuItem newMenu = new JMenuItem("New", newIcon);
    newMenu.setMnemonic(KeyEvent.VK_N);
    newMenu.setToolTipText("Start new document");

    JMenuItem openMenu = new JMenuItem("Open", openIcon);
    openMenu.setMnemonic(KeyEvent.VK_O);
    openMenu.setToolTipText("Open document");

    JMenuItem saveMenu = new JMenuItem("Save", saveIcon);
    saveMenu.setMnemonic(KeyEvent.VK_S);
    saveMenu.setToolTipText("Save document");

    JMenuItem exitMenu = new JMenuItem("Exit", exitIcon);
    exitMenu.setMnemonic(KeyEvent.VK_X);
    exitMenu.setToolTipText("Exit application");
    exitMenu.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent event){
            System.exit(0);
        }
    });
    exitMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, 
            KeyEvent.CTRL_MASK));

    file.add(newMenu);
    file.add(openMenu);
    file.add(saveMenu);
    file.addSeparator();
    file.add(importMenu);
    file.addSeparator();
    file.add(exitMenu);

    menubar.add(file);
    setJMenuBar(menubar);

    JPanel panel = new JPanel();
    getContentPane().add(panel);
    panel.setLayout(null);

    JButton button = new JButton("Quit");
    button.setBounds(100,60,80,40);
    button.setToolTipText("Press");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event){
            System.exit(0);
        }
    });

    panel.add(button);

    setSize(300, 200);
    setTitle("testGUI");
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:47:39+00:00Added an answer on May 23, 2026 at 4:47 pm

    Change it to a JMenu

    JMenu importMenu = new JMenu("Import");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting stair-step output like this My program works correctly, except that when I
This code works correctly to make a web service call: int numberOfGuests = Convert.ToInt32(search.Guest);
I have some Python code that works correctly when I use python.exe to run
Given the following code,the hover function works correctly, but when clicked, loses the clicked_no_event_box
I have a little bit of Javascript that almost works correctly. Here's the code:
Just run into a tricky NSFetchedResultsController problem. The following code works fine in all
Why doesn't following code work correctly in FireFox 3.6? I have tested in IE7,
scrollPosition = window.frames[id].document.body.scrollTop; The above code doesn't work correctly. Please tell me how to
here is my code it shares the folder but that does not work correctly
I wrote few lines of code which doesn't work correctly. Why? Could sb explain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.