Status Bar

Hallo.

I am writing a Java program that comprises several JInternalFrames to display info. However, the main outer JFrame needs a status bar of some sort, e.g. the one that says "Done" at the bottom of your browser. I have added a JLabel to South of the BorderLayout but it doesnt show. If I remove the desktop thing that they say has to be set for the internal frames to show, the label is seen. How can I work around this for the label to be seen, independent of the JInternalFrames?

Thanks.

[512 byte] By [Jamwaa] at [2007-10-2 5:49:59]
# 1
Really need to see some code.Plus I think an empty label takes no space, make sure it has some text (like a space, or somesuch).
mlka at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 2

//- snip

Date date = new Date();

JDesktopPane desktop = new JDesktopPane();

setContentPane(desktop);

getContentPane().add

(new JLabel(String.valueOf(date), JLabel.LEFT), BorderLayout.SOUTH);

//-- snip

This doesnt show the JLabel, but commenting out

//-- snip

// setContentPane(desktop);

//-- snip

the status bar is shown But no JInternalFrames get visible!

Jamwaa at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 3

try setting a preferred size for the JLabel

myLabel.setPreferredSize(new Dimension(200,100));

Usually that may happen because the JDesktop pane takes all the space and does not leave any space for the JLabel. Ie JLabel gets sacrificed for the JDesktop pane because it did not say she requires a certain height.

sim085a at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 4

Please use [url=http://forum.java.sun.com/help.jspa?sec=formatting]code tags[/url]

setContentPane(desktop);

getContentPane().add

SOUTH is part of BorderLayout, but you are setting the content pane to be a Desktop Pane.

You need to use the default Content pane, add the

desktop to the center of it (it uses BorderLayout by default).

getContentPane().add( desktop, BorderLayout.CENTER );

getContentPane().add( myJLabel, BorderLayout.NORTH );

mlka at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 5
> Really need to see some code.> > Plus I think an empty label takes no space, make sure> it has some text (like a space, or somesuch).An empty label has no length, it has the height of the font declared for it (AFAIK).
jwentinga at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 6

> An empty label has no length, it has the height of

> the font declared for it (AFAIK).

JFrame f = new JFrame();

f.add( new JLabel( "content" ), BorderLayout.CENTER ); // fake content

f.add( new JLabel( "" ), BorderLayout.SOUTH ); // fake status bar

f.pack();

f.show();

should then have a high of [Single Line JLabel] * 2, but does not.

mlka at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 7

> Please use

> [url=http://forum.java.sun.com/help.jspa?sec=formattin

> g]code tags[/url]

>

> > setContentPane(desktop);

> getContentPane().add

>

> SOUTH is part of BorderLayout, but you are setting

> the content pane to be a Desktop Pane.

> You need to use the default Content pane, add the

> desktop to the center of it (it uses BorderLayout by

> default).

>

> > getContentPane().add( desktop, BorderLayout.CENTER

> );

> getContentPane().add( myJLabel, BorderLayout.NORTH

> );

>

The above peace of code fails. It refuses to still display the JLabel

Jamwaa at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 8
> The above peace of code fails. It refuses to still> display the JLabelDoes the JLabel have any content (a space say)?
mlka at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 9
Yes. The starting text is "Status: Ready"
Jamwaa at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 10
Post the code
mlka at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 11

> Hallo.

> I am writing a Java program that comprises several

> JInternalFrames to display info. However, the main

> outer JFrame needs a status bar of some sort, e.g.

> the one that says "Done" at the bottom of your

> browser. I have added a JLabel to South of the

> BorderLayout but it doesnt show. If I remove the

> desktop thing that they say has to be set for the

> internal frames to show, the label is seen. How can I

> work around this for the label to be seen,

> independent of the JInternalFrames?

>

> Thanks.

What you might want to do seeing as all the above didn't seem to work is this:

Add a JPanel to the Bottom SOUTH of your GUI, and stick the Label on that, Add the JInternalFrames to the CENTER

something like { I'm making this up so it won't work}

private void makeBigPanel()

{

this.setLayout( new BorderLayout() );

// blah blah blah

// JInternalFrame frame = new JInternalFrame(?);

Container content = this.getContentPane();

// apparently you can skip that now...

content.add( frame, BorderLayout.CENTER );

JPanel statusPanel = new JPanel();

statusPanel.setBorder( BorderFactory.createLineBorder( Color.GREEN) );

JLabel statusLabel = new JLabel(" ");

statusPanel.add( statusLabel );

content.add( statusPanel, BorderLayout.SOUTH );

// Blah b;lah

}

WIlfred_Deatha at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 12

when I try to do this:

setContentPane(desktop, BorderLayout.CENTER);

this is the compiler error that I get:

setContentPane(java.awt.Container) in javax.swing.JFrame cannot be applied to (javax.swing.JDesktopPane,java.lang.String)

a part of the code is:

//snip

// this method makes it possible so that the internal frames are visible

desktop = new JDesktopPane(); //a specialized layered pane

setContentPane(desktop, BorderLayout.CENTER);

desktop.setBackground(Color.GRAY);

getContentPane().add(statusBar, BorderLayout.SOUTH);

// give this window a title, size and location

setTitle("Spin Master");

setDefaultLookAndFeelDecorated(true);

setSize(900, 650);

//snip

This compiles well, but no status bar gets shown. However, on commenting out sone few lines:

//snip

// this method makes it possible so that the internal frames are visible

desktop = new JDesktopPane(); //a specialized layered pane

//setContentPane(desktop, BorderLayout.CENTER);

desktop.setBackground(Color.GRAY);

getContentPane().add(statusBar, BorderLayout.SOUTH);

// give this window a title, size and location

setTitle("Spin Master");

setDefaultLookAndFeelDecorated(true);

setSize(900, 650);

//snip

One sample method I use to add the internal frames is:

private void showAllScores()

{

ScoresDisplayer shower = new ScoresDisplayer();

shower.setVisible(true);

shower.displayAllScores();

desktop.putClientProperty("JDesktopPane.dragMode", "outline");

desktop.add(shower);

try

{

shower.setSelected(true);

}

catch (java.beans.PropertyVetoException bean_error)

{

showInternalFrameDisplayErrorMessage();

}

}

The status bar gets displayed fine, but no internal frames are shown. All I can think of doesnt bear fruit...

Jamwaa at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 13

setContentPane(desktop, BorderLayout.CENTER);

Don't set the content pane to ANYTHING, leave it as the default.

Instead ADD TO the content pane.

getContentPane().add(desktop, BorderLayout.CENTER);

getContentPane().add(status, BorderLayout.SOUTH);

mlka at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...
# 14
Thank you very much. Am running the bar and updating it using static methods as the program runs
Jamwaa at 2007-7-16 1:59:24 > top of Java-index,Java Essentials,New To Java...