我正在创建一个Java应用程序的过程中,希望在应用程序的底部有一个栏,在其中我显示一个文本栏和一个状态(进度)栏。
只是我似乎找不到NetBeans中的控件,我也不知道要在其中手动创建的代码。
发布于 2010-06-14 16:37:11
创建一个带有BorderLayout的JFrame或JPanel,给它一个类似于BevelBorder或线条边框的东西,这样它就可以从其余的内容中分离出来,然后在BorderLayout.SOUTH添加状态面板。
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(200, 200);
// create the status bar panel and shove it down the bottom of the frame
JPanel statusPanel = new JPanel();
statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
frame.add(statusPanel, BorderLayout.SOUTH);
statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 16));
statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
JLabel statusLabel = new JLabel("status");
statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
statusPanel.add(statusLabel);
frame.setVisible(true);下面是我的机器上的上述状态条形码的结果:

发布于 2010-06-14 16:37:56
不幸的是,Swing本身并不支持StatusBars。您可以使用BorderLayout和标签或任何需要显示在底部的内容:
public class StatusBar extends JLabel {
/** Creates a new instance of StatusBar */
public StatusBar() {
super();
super.setPreferredSize(new Dimension(100, 16));
setMessage("Ready");
}
public void setMessage(String message) {
setText(" "+message);
}
}然后在您的主面板中:
statusBar = new StatusBar();
getContentPane().add(statusBar, java.awt.BorderLayout.SOUTH);来自:http://www.java-tips.org/java-se-tips/javax.swing/creating-a-status-bar.html
发布于 2010-06-14 16:38:06
我推荐SwingX library中的状态栏组件--下面是status bar is here的API文档。
A good example of its use is here.
玩得开心。
https://stackoverflow.com/questions/3035880
复制相似问题