Status Bar or any swing component

F

ffellico

Hi.

How I can obtain that a Status bar wil be showed always on the bottom
of a frame, also when someone resize at the run time that Frame?

Same time this is a common problem also for other visual component.

I think that the use of Layouts can do this for me, but I was unable to
realize it, so I think that a sample code referred to a Status bar can
help me in understanding the whole problem. Consider that normally I
use XYLayout for my frames and I need to keep only the StatusBar always
on the bottom.

Thank you. Franco.
 
Z

zero

(e-mail address removed) wrote in @g47g2000cwa.googlegroups.com:
Hi.

How I can obtain that a Status bar wil be showed always on the bottom
of a frame, also when someone resize at the run time that Frame?

Same time this is a common problem also for other visual component.

I think that the use of Layouts can do this for me, but I was unable to
realize it, so I think that a sample code referred to a Status bar can
help me in understanding the whole problem. Consider that normally I
use XYLayout for my frames and I need to keep only the StatusBar always
on the bottom.

Thank you. Franco.

use a BorderLayout.

class MyClass extends JFrame
{
JLabel lblStatusBar = new JLabel();

public MyClass()
{
setLayoutManager(new BorderLayout());
add(lbsStatusBar, BorderLayout.SOUTH);
}

// ...
}

More info:

http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html
http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
 
F

ffellico

Thank you. I solved my problem but it was necessary to change the two
statement you suggest in:

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

In that way it worked but any other component disappears from the
frame, so I create a Panel (jPanel1) in the NORTH part of the frame,
and I put all other components in this Panel; after II add this other
statement:

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

Now when at run time I resize the frame, the statusbar remain always at
the bottom of the frame, jPanel1 expand itself in all the rest of the
space of the frame and the other components ar alway visible in the
location where I have put them.

Please, can you confirm that this is the way to work with Layouts to
solve all this kind of problems?

I am a beginner in Java (I worked until now in Delphi) so I need to
understant this different architecture.

Tank you again. Franco.
 
Z

zero

(e-mail address removed) wrote in @g43g2000cwa.googlegroups.com:
Thank you. I solved my problem but it was necessary to change the two
statement you suggest in:

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

In that way it worked but any other component disappears from the
frame, so I create a Panel (jPanel1) in the NORTH part of the frame,
and I put all other components in this Panel; after II add this other
statement:

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

Now when at run time I resize the frame, the statusbar remain always at
the bottom of the frame, jPanel1 expand itself in all the rest of the
space of the frame and the other components ar alway visible in the
location where I have put them.

Please, can you confirm that this is the way to work with Layouts to
solve all this kind of problems?

I am a beginner in Java (I worked until now in Delphi) so I need to
understant this different architecture.

Tank you again. Franco.

Yep that's exactly how it's done. The JPanel can itself have any layout
you want, creating increasingly complex GUIs. Have a look at the other
layout managers, and pick whatever is best for each specific situation.

For a good introduction in Swing layout managers I suggest the excellent
java swing tutorial, see the links in my previous post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top