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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:11:22+00:00 2026-06-10T23:11:22+00:00

I have been experimenting with making GUIs in java as opposed to just using

  • 0

I have been experimenting with making GUIs in java as opposed to just using “static” all the time and come across the “SwingUtilities.invokeLater()” method. I manage to get everything setup but when it comes to run the application, nothing appears on the JPanel until I resize the window. Is there a fix for this or am I doing it wrong?

Heres my code:

public class main extends JPanel implements ActionListener{ 
public JLabel userLabel;
public JLabel passLabel;
public JTextField userField;
public JTextField passField;
public JButton login;
public JButton closeLogin;
public JButton help;

public main(){
    userLabel = new JLabel("Username: ");
    passLabel = new JLabel("Password: ");
    userField = new JTextField(16);
    passField = new JTextField(16);

    login = new JButton("Login");
    login.setActionCommand("login");
    login.setMnemonic(KeyEvent.VK_L);
    closeLogin = new JButton("Close");
    closeLogin.setActionCommand("closeLogin");
    closeLogin.setMnemonic(KeyEvent.VK_E);
    help = new JButton("Help");
    help.setActionCommand("helpLogin");
    help.setMnemonic(KeyEvent.VK_H);

    login.addActionListener(this);
    closeLogin.addActionListener(this);
    help.addActionListener(this);

    add(userLabel);
    add(userField);
    add(passLabel);
    add(passField);
    add(login);
    add(help);
    add(closeLogin);

}
public void actionPerformed(ActionEvent e){ 
}
public static void initComponents(){
    JFrame loginFrame = new JFrame("Encrypted Chat - Login");
    loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    main loginPanel = new main();
    loginPanel.setLayout(new FlowLayout());
    loginFrame.setSize(300, 125);
    loginFrame.setResizable(false);
    loginFrame.setVisible(true);        
}
public static void main(String args[]){
    SwingUtilities.invokeLater(new Runnable(){
        public void run(){
            initComponents();
        }
    });
}

}

EDIT: I know the password JTextField is meant to be a JPasswordField.. so ignore it 😛

  • 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-06-10T23:11:24+00:00Added an answer on June 10, 2026 at 11:11 pm

    You never add your content to the JFrame. The minimal set of changes you need:

      public static void main(String args[]){
        final main main = new main();
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            initComponents(main);
          }
        });
      }
    

    And then modify initComponents to take a main object:

      public static void initComponents(main main){
        JFrame loginFrame = new JFrame("Encrypted Chat - Login");
        loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        main loginPanel = new main();
        loginPanel.setLayout(new FlowLayout());
        loginFrame.setSize(300, 125);
        loginFrame.setResizable(false);
        loginFrame.setVisible(true);
        loginFrame.add(main);  // <----- this line is added
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've been experimenting with javascript's prototypal inheritance and have come across something that perhaps
I have been experimenting with templating in js and have come across a pretty
I have been experimenting with sending messages from two .NET Windows Forms applications using
I have been experimenting some problems with the fully distributed version. First of all
I have been experimenting recently with Silverlight, RIA Services, and Entity Framework using .NET
I have been experimenting with using javascript to dynamically write stylesheets. In Firefox, one
I have been experimenting with LINQ to XML and have run across a very
I have been experimenting using a Facebook login button on my website. The login
I have been looking at making the switch from SQL TableAdapters to Linq using
I have been experimenting on making a random map for a top down RPG

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.