Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2005

Tip: Looking for answers? Try searching our database.

Statusbar class in official library?

Thread view: 
Matthias Kaeppler - 05 Jun 2005 21:21 GMT
Hi,

I couldn't find any class in the API reference realizing a statusbar,
which can be placed at the bottom of a window.

Is there really no such class in the Java Standard Library?

Signature

Matthias Kaeppler

Dave Programmer - 05 Jun 2005 21:58 GMT
Not sure what exactly you mean by "statusbar". There is a progress bar
component (javax.swing.JProgressBar).
Andrew McDonagh - 05 Jun 2005 22:17 GMT
> Hi,
>
> I couldn't find any class in the API reference realizing a statusbar,
> which can be placed at the bottom of a window.
>
> Is there really no such class in the Java Standard Library?

no, but its simple enough to create your own using a JPanel.
Chris Smith - 06 Jun 2005 02:29 GMT
> I couldn't find any class in the API reference realizing a statusbar,
> which can be placed at the bottom of a window.
>
> Is there really no such class in the Java Standard Library?

The question really boils down to this: what exactly do you want a
status bar to do, above and beyond what you can do with a JPanel,
configured with a BoxLayout or SpringLayout, containing instances of
JLabel, and have a border set on it with JComponent.setBorder?

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Matthias Kaeppler - 06 Jun 2005 09:26 GMT
>>I couldn't find any class in the API reference realizing a statusbar,
>>which can be placed at the bottom of a window.
[quoted text clipped - 5 lines]
> configured with a BoxLayout or SpringLayout, containing instances of
> JLabel, and have a border set on it with JComponent.setBorder?

Easy: Only care about one widget instead of 4 or 5. :)

Signature

Matthias Kaeppler

Thomas Weidenfeller - 06 Jun 2005 10:14 GMT
> Easy: Only care about one widget instead of 4 or 5. :)

Since the contents and organization of a status bar varies from
application to application: How complex do you like to have the API and
configuration of your one ultimate status bar widget?

Divide et impera.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

IchBin - 06 Jun 2005 03:34 GMT
> Hi,
>
> I couldn't find any class in the API reference realizing a statusbar,
> which can be placed at the bottom of a window.
>
> Is there really no such class in the Java Standard Library?

There is none that I know of out there. You can usually just use a label
object. I added a Green\Red button and a status area in the HSQLDB 1.8.0
DatabaseSwingManager class.

You can down load the code from

http://sourceforge.net/project/showfiles.php?group_id=23316

Looks like the current release candidate of 1.8.0 is RC11.

I have a screenshot of it at my site..

Sorry for the IP address as I am using my machine t host site.

http://24.115.55.47:8080/JHackerAppManager

....under Other Software Tab.
Signature


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
__________________________________________________________________________

' If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)

Thomas Kellerer - 06 Jun 2005 10:12 GMT
> Hi,
>
> I couldn't find any class in the API reference realizing a statusbar,
> which can be placed at the bottom of a window.
>
> Is there really no such class in the Java Standard Library?

Why don't you use a JLabel if you only want to display text there.

Thomas
Matthias Kaeppler - 06 Jun 2005 10:17 GMT
> Hi,
>
> I couldn't find any class in the API reference realizing a statusbar,
> which can be placed at the bottom of a window.
>
> Is there really no such class in the Java Standard Library?

I have now come up with this code:

    private class StatusBar extends JPanel {
   
    StatusBar() {
       statusText.setAlignmentX( JComponent.LEFT_ALIGNMENT );
       //setAlignmentX( JComponent.LEFT_ALIGNMENT );
       add( statusText );
       int width  = (int) getMaximumSize().getWidth();
       int height = (int) getPreferredSize().getHeight();
       setMaximumSize( new Dimension(width,height) );
       setBorder( new EtchedBorder() );
    }

    void setText( String text ) {
       statusText.setText( text );
    }
    private JLabel statusText = new JLabel();
    }

I want the text to be aligned left, but it's centered by default.
However, neither setAlignmentX( LEFT_ALIGNMENT ) nor
statusText.setAlignmentX( LEFT_ALIGNMENT ) seem to work. The first will
shrink the whole JPanel component, the latter has (at least visually) no
effect at all.

Any ideas?

Signature

Matthias Kaeppler

Thomas Weidenfeller - 06 Jun 2005 10:26 GMT
> I want the text to be aligned left, but it's centered by default.
> However, neither setAlignmentX( LEFT_ALIGNMENT ) nor
[quoted text clipped - 3 lines]
>
> Any ideas?

http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Thomas Kellerer - 06 Jun 2005 10:38 GMT
> I want the text to be aligned left, but it's centered by default.
> However, neither setAlignmentX( LEFT_ALIGNMENT ) nor
> statusText.setAlignmentX( LEFT_ALIGNMENT ) seem to work. The first will
> shrink the whole JPanel component, the latter has (at least visually) no
> effect at all.

>         statusText.setAlignmentX( JComponent.LEFT_ALIGNMENT );

should be setHorizontalAlignment()

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JLabel.html#setHorizontalAli
gnment(int
)

Thomas
Matthias Kaeppler - 06 Jun 2005 16:40 GMT
>>I want the text to be aligned left, but it's centered by default.
>>However, neither setAlignmentX( LEFT_ALIGNMENT ) nor
[quoted text clipped - 9 lines]
>
> Thomas

That still doesn't work:

    statusText.setHorizontalAlignment( SwingConstants.LEFT );

The text is still centered. I think it may be because I'm using a flow
layout, as already pointed out. Maybe I should really switch to a
BoxLayout or such.

Signature

Matthias Kaeppler

Matthias Kaeppler - 06 Jun 2005 16:48 GMT
>>> I want the text to be aligned left, but it's centered by default.
>>> However, neither setAlignmentX( LEFT_ALIGNMENT ) nor
[quoted text clipped - 17 lines]
> layout, as already pointed out. Maybe I should really switch to a
> BoxLayout or such.

Now (after using BoxLayout), the label isn't visible anymore o_O

    private class StatusBar extends JPanel {
   
    StatusBar() {
       setLayout( new BoxLayout(this, BoxLayout.LINE_AXIS) );
       statusText.setHorizontalAlignment( SwingConstants.LEFT );
       setAlignmentX( JComponent.LEFT_ALIGNMENT );
       add( statusText );
       int width  = (int) getMaximumSize().getWidth();
       int height = (int) getPreferredSize().getHeight();
       setMaximumSize( new Dimension(width,height) );
       setBorder( new EtchedBorder() );
    }

    void setText( String text ) {
       statusText.setText( text );
    }
    private JLabel statusText = new JLabel();
    }

To the guy who asked why I want such a class to be in the library:
The reason is one wasted hour (and counting) trying to write my own :-/

Signature

Matthias Kaeppler

Thomas Kellerer - 06 Jun 2005 17:00 GMT
>     private class StatusBar extends JPanel {
>    
[quoted text clipped - 13 lines]
>     }
>     private JLabel statusText = new JLabel();
What about:

setLayout(new BorderLayout())
...

add(statusText, BorderLayout.CENTER);

Thomas
Matthias Kaeppler - 06 Jun 2005 17:49 GMT
>>    private class StatusBar extends JPanel {
>>    
[quoted text clipped - 22 lines]
>
> Thomas

I decided to use a GridLayout now. This also makes sure the components
are always resized to fill the container (which is good for my purpose).

Thanks.

Signature

Matthias Kaeppler

Chris Smith - 06 Jun 2005 13:27 GMT
> I want the text to be aligned left, but it's centered by default.
> However, neither setAlignmentX( LEFT_ALIGNMENT ) nor
[quoted text clipped - 3 lines]
>
> Any ideas?

The fundamental problem is that you're using FlowLayout, which means
that the label itself is not going to take up the entire status bar
component.  If you really only want one piece of text on the bar, then
skip the JPanel and use a JLabel for the text.  If you need several
things, then perhaps a horizontal BoxLayout would be better.

Once you've got a decent layout, then a simple call to the
JLabel.setHorizontalAlignment method (as Thomas Kellerer suggested) will
work fine, although it's really unnecessary since JLabel defaults to
left alignment.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.