Frame Label display question

OK. This sounds stupid but I wanted to display to my users a simple status box so I used the following code....

JFrame gui =new JFrame();

JLabel label =new JLabel("Checking Comp Plan Costs 0%");

gui.getContentPane().add(label, java.awt.BorderLayout.CENTER);

gui.pack();

gui.setVisible(true);

The frame appears and seems sized correctly but there is no text displayed.

However, if I use Frame instead of JFrame it displays the text.

Thanks for any help.

[633 byte] By [souLTowera] at [2007-10-2 20:26:06]
# 1
I am not sure whether the border layout is the default layout manager for the JFrame so just set the layout manager yourself to BorderLayout and see.
LRMKa at 2007-7-13 23:09:04 > top of Java-index,Java Essentials,Java Programming...
# 2

Could you create a small example that shows the problem, or post more code, as that works fine.

import javax.swing.*;

public class Test {

public static void main(String argv[] ) throws Throwable {

JFrame gui = new JFrame();

JLabel label = new JLabel("Checking Comp Plan Costs 0%");

gui.getContentPane().add(label, java.awt.BorderLayout.CENTER);

gui.pack();

gui.setVisible(true);

}

}

Also, it looks like you are using it as a [url=http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/ProgressMonitor.html]progress monitor[/url].

mlka at 2007-7-13 23:09:04 > top of Java-index,Java Essentials,Java Programming...
# 3

> I am not sure whether the border layout is the

> default layout manager for the JFrame so just set the

> layout manager yourself to BorderLayout and see.

I'm sure it is specified in the API docs somewhere.

<checks apis/>

<googles/>

But I can not find it now.

mlka at 2007-7-13 23:09:04 > top of Java-index,Java Essentials,Java Programming...
# 4

I feel retarded. I've tried not setting the layout position, setting the layout manager, it's 3 friggin lines of code that just don't work as I would think they would.

It must be a threading issue or something like that. When I run the code in a test class by itself it works.

I'll keep digging. Thanks for the help.

souLTowera at 2007-7-13 23:09:04 > top of Java-index,Java Essentials,Java Programming...
# 5
> but I wanted to display to my users a simple status boxif you're using the EDT to do some 'longTask', then"It must be a threading issue or something like that. "would be correct.try a ProgressMonitor
Michael_Dunna at 2007-7-13 23:09:04 > top of Java-index,Java Essentials,Java Programming...
# 6
Are you doing this long task in the AWT event thread?
mlka at 2007-7-13 23:09:04 > top of Java-index,Java Essentials,Java Programming...