How can I create a bar in the bottom of a Java app, like a status bar?

前端 未结 5 877
谎友^
谎友^ 2020-12-12 17:07

I am in the process of creating a Java app and would like to have a bar on the bottom of the app, in which I display a text bar and a status (progress) bar.

Only I c

5条回答
  •  感动是毒
    2020-12-12 17:52

    Unfortunately Swing does not have a native support for StatusBars. You can use a BorderLayout and a label or whatever you need to display at the bottom:

    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);        
        }        
    }
    

    Then in your Main Panel:

    statusBar = new StatusBar();
    getContentPane().add(statusBar, java.awt.BorderLayout.SOUTH);
    

    From: http://www.java-tips.org/java-se-tips/javax.swing/creating-a-status-bar.html

提交回复
热议问题