File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to add a Status Bar in a frame(at the Bottom ofcourse) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to add a Status Bar in a frame(at the Bottom ofcourse)" Watch "How to add a Status Bar in a frame(at the Bottom ofcourse)" New topic
Author

How to add a Status Bar in a frame(at the Bottom ofcourse)

Murali Obla
Ranch Hand

Joined: Nov 18, 2001
Posts: 40
Hello Folks,
How would I add a Status Bar at the Bottom of the frame in Swings.Is there any component.
Thanks in Advance,
Murli


"Excellence is never an accident; it is always the result of high intention, sincere effort, intelligent direction, skillful execution, and the vision to see obstacles as opportunities"
Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
Use JProgressBar. Check API for details


Pete<br />"Reality is an illusion <br />brought on by a lack of <br />drink, drugs and smut"
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
Hi murali,
here is an example on the statusBar.
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame
{
public Main()
{
getContentPane().setLayout(new BorderLayout());
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Sex");
JMenuItem menuItem1 = new JMenuItem("male");
JMenuItem menuItem2 = new JMenuItem("female");
JMenuItem menuItem3 = new JMenuItem("androgyne");
// add the MenuItems to the Menu
menu.add(menuItem1);
menu.add(menuItem2);
menu.add(menuItem3);
StatusBar statusBar = new StatusBar();
new JMenuItemHelpText(menuItem1, "The weak sex", statusBar);
new JMenuItemHelpText(menuItem2, "The strong sex", statusBar);
new JMenuItemHelpText(menuItem3, "The average sex, I guess", statusBar);
menuBar.add(menu);
this.setJMenuBar(menuBar);
getContentPane().add(BorderLayout.SOUTH, statusBar);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event)
{
System.exit(0);
}
});
setSize(400, 400);
}
public static void main(String[] args)
{
(new Main()).show();
}
}
class JMenuItemHelpText implements ChangeListener
{
JMenuItem menuItem;
String helpText;
StatusBar statusBar;
JMenuItemHelpText(JMenuItem menuItem, String helpText, StatusBar statusBar)
{
this.menuItem = menuItem;
this.helpText = helpText;
this.statusBar = statusBar;
menuItem.addChangeListener(this);
}
public void stateChanged(ChangeEvent evt)
{
if (menuItem.isArmed())
statusBar.setStatus(helpText);
else
statusBar.setStatus("");
}
}

class StatusBar extends JPanel
{
private JLabel statusLabel;
public StatusBar()
{
setLayout(new BorderLayout(2, 2));
statusLabel = new JLabel("Ready");
statusLabel.setBorder(BorderFactory.createLoweredBevelBorder());
statusLabel.setForeground(Color.black);
add(BorderLayout.CENTER, statusLabel);
JLabel dummyLabel = new JLabel(" ");
dummyLabel.setBorder(BorderFactory.createLoweredBevelBorder());
add(BorderLayout.EAST, dummyLabel);
}
public void setStatus(String status)
{
if (status.equals(""))
statusLabel.setText("Ready");
else
statusLabel.setText(status);
}
public String getStatus()
{
return statusLabel.getText();
}
}
cheers,
Raj
Murali Obla
Ranch Hand

Joined: Nov 18, 2001
Posts: 40
Thanks Pete
Thanks for ur code Rajendar,
Cool it is working,
I am really gainin' some Swings knowledge ,
Murli
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add a Status Bar in a frame(at the Bottom ofcourse)
 
Similar Threads
how to set statues of Dialog?
frame decoration problem
How many chars in statusbar?
Status display
JFrame in applet