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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:36:12+00:00 2026-05-20T23:36:12+00:00

I am trying to write a simple desktop application for managing accounts. I am

  • 0

I am trying to write a simple desktop application for managing accounts. I am in the beginning phase.

I am running it in my old computer and I sometimes get strange behavior.

Java Version

java version “1.6.0_05”
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

My computer configuration

Microsoft Windows XP SP2
Intel(R) Celeron(R) CPU 2.53GHz 1.96GHz 736MB of RAM

I get strange behaviour. When I compile my program and the jframe loads, i sometimes get menu and sometimes I don’t get menu as shown in the figure. Also when I try to resize my jframe, jframe shows menu.

My code

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

public class Main {

    public static void main(String[] args) {
        new Login();
    }

}

class Login extends JFrame{

    private int height=450;
    private int width=300;

    private Container container;
    private GridBagLayout layout;
    private GridBagConstraints constraints; 

    JTextArea textArea1, textArea2;

    public Login()
    {
        initWindow();
        initMenu();             
    }

    private void initWindow()
    {           
        setVisible(true);       
        setSize(this.height, this.width);       
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Toolkit toolkit =  Toolkit.getDefaultToolkit ();        
        Dimension dim = toolkit.getScreenSize();
        setLocation((dim.width-this.width)/2, (dim.height-this.height)/2);

        Image image = toolkit.createImage("account.gif");
        setIconImage(image);
    }

    private void initMenu()
    {
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);

        JMenu fileMenu = new JMenu("File");     
        JMenu helpMenu = new JMenu("Help");

        menuBar.add(fileMenu);      
        menuBar.add(helpMenu);

        JMenuItem configureAction = new JMenuItem("Configure");
        JMenuItem exitAction = new JMenuItem("Exit");

        fileMenu.add(configureAction);
        fileMenu.add(exitAction);

        JMenuItem helpAction = new JMenuItem("Help");
        JMenuItem aboutAction = new JMenuItem("About");

        helpMenu.add(helpAction);
        helpMenu.add(aboutAction);
    }   
}

Window with no menu

No menu fig

Window with menu

enter image description here

Any suggestion to improve code with be highly appreciated.

Thank you

  • 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-20T23:36:13+00:00Added an answer on May 20, 2026 at 11:36 pm

    Don’t call setVisible(true) until the window is completely built, ie. do that statement as the last thing you do with the window.

    Once the window is visible, any changes you make to the window must be done on the GUI thread.

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

Sidebar

Related Questions

I'm trying to write a super-simple podcast-to-device downloading service to use for running. I
I am trying to write a simple application that runs on a Windows Mobile
I am trying to write simple Visual Studio Add-In for code generation. In my
I'm trying to write a simple game/utility to calculate poker odds. I know there's
I'm trying to write a simple program in VC++ which will just initialize the
I'm trying to write a simple WPF app that has two ellipses, joined by
I'm trying to write a simple raytracer as a hobby project and it's all
I'm just starting out writing trying to write a simple program in C and
I am trying to write a really simple Outlook VSTO add in that checks
I'm trying to think of clever, clear, and simple ways to write code that

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.