Why is the GUI not showing when i run it

Why is it not showing the container

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.*;

publicclass Progressextends JFrame{

private String path;

private JPanel topLeftPanel;

private JPanel labelPanel;

private JTextField pathField;

public Progress()

{

this.setTitle("PROGRESS Message Viewer");

this.setSize(800, 600);

Container contentPane = this.getContentPane( );

// Technique for centering a frame on the screen.

Dimension frameSize = this.getSize();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

this.setLocation((screenSize.width - frameSize.width)/2,

(screenSize.height - frameSize.height)/2);

topLeftPanel =new JPanel();

topLeftPanel.setLayout(new GridLayout(1, 2));

labelPanel =new JPanel();

labelPanel.setLayout(new GridLayout(4, 1));

JLabel l =new JLabel("Please enter the path to log file: ");

l.setForeground(Color.black);

labelPanel.add(l);

topLeftPanel.add(labelPanel);

pathField =new JTextField(80);

ActionListener aListener =new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

// Retrieve the path.

char[] pathFieldText = pathField.getText().toCharArray();

path =new String(pathFieldText).trim();

}

};

pathField.addActionListener(aListener);

contentPane.add(topLeftPanel);

contentPane.add(pathField);

}

publicstaticvoid main(String []args){

Progress p =new Progress();

}

}

[2919 byte] By [SDNJavaa] at [2007-11-27 7:27:54]
# 1
You never made it visible!
Hippolytea at 2007-7-12 19:08:09 > top of Java-index,Java Essentials,Java Programming...
# 2

> // Technique for centering a frame on the screen.

>

> Dimension frameSize = this.getSize();

> Dimension screenSize =

> = Toolkit.getDefaultToolkit().getScreenSize();

> this.setLocation((screenSize.width -

> - frameSize.width)/2,

> (screenSize.height -

> screenSize.height - frameSize.height)/2);

methods are better than techniques:

JFrame.setLocationRelativeTo(null); // centers jframe

TuringPesta at 2007-7-12 19:08:09 > top of Java-index,Java Essentials,Java Programming...
# 3
I don't see a setVisible(true) anywhere!
sabre150a at 2007-7-12 19:08:09 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks guys. Thanks for the tip TuringPest about setLocationRelativeTo(null);
SDNJavaa at 2007-7-12 19:08:09 > top of Java-index,Java Essentials,Java Programming...
# 5
OK, now i can see container but it is not showing the panel that i added e.g. label and textfield.
SDNJavaa at 2007-7-12 19:08:09 > top of Java-index,Java Essentials,Java Programming...
# 6
I think this last line in the constuctor: contentPane.add(pathField);causes the JTextField pathField to be added to the center of the contentPane,and subsequently stretched to fill the client area. Try typing in something. Your window is one big text field.
Hippolytea at 2007-7-12 19:08:09 > top of Java-index,Java Essentials,Java Programming...
# 7

Swing related questions should be posted in the Swing forum.

Read the BoderLayout API documentation. If you don't specify a constraint then by default the component is added to the "CENTER". However only a single component can be displayed in any given area of the BorderLayout. So the second add(...) method replaces the first component added.

Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers[/url] for more information.

camickra at 2007-7-12 19:08:09 > top of Java-index,Java Essentials,Java Programming...