Learn how to a build a cloud-first strategyRegister Now


Java window component bug

Posted on 2009-04-15
Medium Priority
Last Modified: 2013-11-23
Given the below java code:

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

public class WindowSwing {
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("Windows Asgn");
        frame.setSize(400, 150);

        //Create container
        Container content = frame.getContentPane();

        //Add JButton
        JButton button = new JButton("JButton");

        //Add JLabel.
        JLabel label = new JLabel("Enter Your First Name Below:");

        //Add JtextField
        JTextField textFld = new JTextField();

        //Display the window.
        //frame.addWindowListener(new ExitListener());

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {

The window run is very small. None of the components show. Why? Please advise.
Question by:ksfok
1 Comment
LVL 92

Accepted Solution

objects earned 2000 total points
ID: 24154688
because default layout is BorderLayout so each component you add replaces the previous
either use a different layout manager, or specify different borderlayout *areas* for each


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month20 days, 21 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question