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

  • Home
  • SEARCH
  • 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 8811435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:21:52+00:00 2026-06-14T03:21:52+00:00

I have Ex1 below: main(String args[]) { JFrame frame = new JFrame(Title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton

  • 0

I have Ex1 below:

main(String args[]) {
    JFrame frame = new JFrame("Title");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Press Here");
    ContainerListener container = new ContainerAdapter() {
      public void componentAdded(final ContainerEvent e) {
          System.out.println("On the event thread? : " +
                  EventQueue.isDispatchThread());
      }
    };
    frame.getContentPane().addContainerListener(container);
    frame.add(button, BorderLayout.CENTER);
    frame.setSize(200, 200);
    System.out.println("I'm about to be realized: " +
      EventQueue.isDispatchThread());
    frame.setVisible(true);
  }

My result is: On the event thread? : FALSE | I’m about to be realized: false

Other Ex2:

public class GridBagLayoutTester
    extends JPanel implements ActionListener{   
public GridBagLayoutTester() {
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    JButton button = new JButton("Testing");
    // do something...
    button.addActionListener(this);
    add(button, gbc);
}

public void actionPerformed(ActionEvent e) {
    System.out.println("On the event thread? : " +
                  EventQueue.isDispatchThread());
}

public static void main(String[] args) {
    JFrame frame = new JFrame("GridBagLayoutDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(new GridBagLayoutTester(), BorderLayout.CENTER);
    frame.setSize(800, 600);
    frame.pack();
    frame.setVisible(true);
    System.out.println("I'm about to be realized: " +
      EventQueue.isDispatchThread());
}   

}

result is: I’m about to be realized: false | On the event thread? : TRUE

My question is why Ex1- componentAdded() run in Intial Thread, but Ex2- actionPerformed() run in EDT ?

  • 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-14T03:21:53+00:00Added an answer on June 14, 2026 at 3:21 am

    Your very first line in the main method creates a new object of type JFrame. This creation starts a new thread (in reality it starts more than one thread) – a new thread that waits for event queue items. This can be a mouse click for example.
    To answer your question: The main thread – which is really called “main” – is invoking your 10 lines of code of the main method. This should be finished in some milliseconds. After that the main thread is gone, not existend anymore.
    But as I said before, the AWT/Swing library has internally created one (yes, more) thread that is basically an ininite loop checking for user input. And the actionPerformed method is invoked from this thread.

    My suggestion for you:

    • Create a breakpoint in your first line of the main method.

    • Debug your program.

    • When the debugger stops at line one (before JFrame is created) go to your command line and start jconsole

    • go to tab threads

    • notice thread “main”

    • execute single line (new JFrame)

    • notice coexistence of thread “main” and thread(s) “AWT-*”

    • press play on debugger and “main” will be gone but AWTs will persist

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

Sidebar

Related Questions

I have some like that. <script src=http://code.jquery.com/jquery-latest.js></script> <table> <tr title=test id=ex1> <td><div class=move>Hello</div></td> <td>&nbsp;</td>
I have three difference examples mention below. I don't understand why ex1 has same
I have the following type of data ex1 <- data.frame (A = 1:6, B
For example, I have 10 source files named ex1.c , ex2.c , ex3.c ....
Making this tutorial: http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html I have ListActivity-derived class and onCreateContextMenu, onContextItemSelected overrides. I think
I have a string and I want to decode into json. The string was
I am completely new to Batch files and have been tinkering around with simple
I have two html pages that two javascript functions. page1.html <a href=page2.html onclick=ex1()>link1</a> page2.html
I have a problem compiling the following code: #include <stdio.h> #include <limits.h> int main
I Have some request like below : $input = $POS,1234,5223,A,2719; If get a request

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.