kro*_*ock 102
使用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);
Run Code Online (Sandbox Code Playgroud)
以下是我的机器上的上述状态条形码的结果:
不幸的是,Swing没有对StatusBars的原生支持.您可以使用a 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);
}
}
Run Code Online (Sandbox Code Playgroud)
然后在主面板中:
statusBar = new StatusBar();
getContentPane().add(statusBar, java.awt.BorderLayout.SOUTH);
Run Code Online (Sandbox Code Playgroud)
来自:http://www.java-tips.org/java-se-tips/javax.swing/creating-a-status-bar.html