Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Use JProgressBar. Check API for details
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Thanks Pete
Thanks for ur code Rajendar,
Cool it is working,
I am really gainin' some Swings knowledge ,
Murli
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 9284 times.
Similar Threads
frame decoration problem
How many chars in statusbar?
JFrame in applet
how to set statues of Dialog?
Status display
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:17:39.