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 7440109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:48:06+00:00 2026-05-29T10:48:06+00:00

When I select run file to test my code the GUI application’s menu bar

  • 0

When I select run file to test my code the GUI application’s menu bar does not consistently appear. I’m using NetBeans IDE version 7.0.1. I’m testing the code by selecting anywhere within the code, right clicking the mouse and selecting Run File from the resulting menu. The resulting GUI application has the menu bar but when I rerun the application the menu bar is not there but when I rerun it the menu bar appears.
Perhaps you can test to see if you are having the same problem when you run the program? Is there some sort of residual memory thing going on that I need to purge before I run the program? Here’s the code:

public static void main(String[] args) {
    JFrame main = new JFrame("Main");
    main.setVisible(true);
    main.setSize(600, 600);
    main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints contraints = new GridBagConstraints();
    main.getContentPane().add(panel, BorderLayout.NORTH);
    contraints.gridx = 0;
    contraints.gridy = 0;
    contraints.insets = new Insets(0,0,0,0);

    //Adding labels and buttons
    JLabel enterUserName = new JLabel("Enter User Name:");
    contraints.gridx = 0;
    contraints.gridy = 1;
    contraints.insets = new Insets(1, 1, 1, 1);
    panel.add(enterUserName, contraints);
    JLabel enterPassWord = new JLabel("Enter Password:");
    contraints.gridx = 0;
    contraints.gridy = 2;
    contraints.insets = new Insets(1, 1, 1, 1);
    panel.add(enterPassWord, contraints);
    JButton logInButton = new JButton("Login");
    contraints.gridx = 0;
    contraints.gridy = 3;
    contraints.insets = new Insets(1, 1, 1, 1);
    panel.add(logInButton, contraints);
    logInButton.addActionListener(new helpAbout());


    //Adding menu bar and menubar items
    JMenuBar menuBar = new JMenuBar();
    main.setJMenuBar(menuBar);
    contraints.gridx = 0;
    contraints.gridy = 0;
    contraints.insets = new Insets(0, 0, 0, 0);
    JMenu file = new JMenu("File");
    menuBar.add(file, contraints);
    JMenu help = new JMenu("Help");
    menuBar.add(help, contraints);

    //Adding menu bar functionality
    JMenuItem exit = new JMenuItem("Exit");
    file.add(exit);
    exit.addActionListener(new fileExit());
    JMenuItem about = new JMenuItem("About");
    help.add(about);
    about.addActionListener(new helpAbout());
}

static class helpAbout implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        JFrame test = new JFrame("About");
        test.setVisible(true);
        test.setSize(200, 200);
        JLabel label2 = new JLabel("About");
        JPanel panel2 = new JPanel();
        test.add(panel2);
        panel2.add(label2);
    }
}

static class fileExit implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        System.exit(0);
    }
}
  • 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-29T10:48:07+00:00Added an answer on May 29, 2026 at 10:48 am

    Call setVisible(true) after building the frame.

    If you add layout/controls to a visible form, which you might want to do in other situations, you need to call revalidate() on the frame/panel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how to assign a test file in resharper? whenever I select 'run tests' it
With SQL Server 2005 using SSMS, when I run this: SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel
When I run the this select '$(''test'')' in SQL Management Studio 2008 it returns
I'd like to run unit test for a functions library file... that is, I
How to select all columns from tables in join using linq Sql: select CTRL_RUN_JOB.*,
I'm creating a small forum. Attempting to run SElECT... JOIN... query too pick up
Today I run this select 'exec sp_refreshview N''['+table_schema+'].['+table_name+']''' from information_schema.tables where table_type = 'view'
Can I run a select statement and get the row number if the items
SQL Server 2005 I have 10 million rows in DB, and run a select
If I run the following SQL query SELECT * FROM A LEFT JOIN B

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.