进来再贴下带注释的,最好能说明下实现的情况~~让我学习下~~~~

解决方案 »

  1.   

    /*
    Java通过布局管理器实现控件的排列。常用的有:
        BorderLayout    (Container默认使用)
        BoxLayout 
        CardLayout 
        FlowLayout        (JPanel默认使用)
        GridBagLayout 
        GridLayout 
        SpringLayout 本程序用到BorderLayout和BoxLayout。*//*
     * 程序主要包括3个类 
     *    StatTextPane:主界面
     *    PlainTextPane:本想用来JTextArea的一些功能,没时间了。
     *    StatusBar:本程序实现的主要功能,提供addIndicator方法
     *               供StatTextPane使用,以添加状态显示格。
     */import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Label;
    import java.awt.Dimension;import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.border.BevelBorder;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.SoftBevelBorder;public class StatTextPane extends JPanel {    public static void main(String[] args) {
            JFrame fr = new JFrame();
            fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        fr.getContentPane().add(new StatTextPane());        fr.setPreferredSize(
                new Dimension(640, 480));        fr.pack();        // 居中显示
            Dimension screen = 
                java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            fr.setLocation(
                (screen.width - fr.getWidth()) / 2,
                (screen.height - fr.getHeight()) / 2);        fr.setVisible(true);
        }    protected PlainTextPane editor;    protected StatusBar statusBar;    public StatTextPane() {
            setLayout(new BorderLayout());        editor = new PlainTextPane();
            statusBar = new StatusBar();        add(new JScrollPane(editor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
                    BorderLayout.CENTER);
            add(statusBar, BorderLayout.PAGE_END);        // 调用方法,增加显示格。根据需要调整次序。
            statusBar.addIndicator(new JLabel("Hello"));
            statusBar.addIndicator(new JLabel("Good"));
            statusBar.addIndicator(new JButton("haha"));
        }
    }class PlainTextPane extends JTextArea {    public PlainTextPane() {
            setBorder(new BevelBorder(BevelBorder.LOWERED));
        }
    }//class StatusBar extends JComponent {
    class StatusBar extends JPanel {    static int HEIGHT = 18;
        static Dimension XGAP = new Dimension(2, 0);
        static Dimension NOTICE_MIN_SIZE = new Dimension(50, HEIGHT);
        static Color BKCOLOR = Color.LIGHT_GRAY;    // 原来是JComponent。现在可以直接利用JLabel的功能显示字符串
        JLabel notice;    public StatusBar() {
            setBackground(Color.LIGHT_GRAY);        // 增加周围的空白,使显示格有垂直居中的效果。
            // 数字依次表示:Top、Left、Bottom、Right。参见API Spec。
            setBorder(new EmptyBorder(2, 0, 2, 2));        // 使用BoxLayout做布局管理器。
            setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
            // 因为StatusBar通常都在窗口的底部,往往是BorderLayout.PAGE_END。
            // 所以提前添加一个刚性支撑,否则StarBar会被压扁。
            add(Box.createRigidArea(new Dimension(0, HEIGHT)));
            // 创建匿名类,扩展JLabel
            notice = new JLabel() {
                // 当创建完或窗口大小改变时,LayoutManager会调用
                // 这两个方法,以调整其大小。            // 返回最小尺寸。你会发现窗口宽度到一定大小时就不能
                // 再减少了。
                public Dimension getMinimumSize() {
                    return new Dimension(50, HEIGHT);
                }            // 最大尺寸。可以设置的足够大,以使其填补可能有的空白。
                public Dimension getMaximumSize() {
                    return new Dimension(5000, 100);
                }
            };
            notice.setBorder(
                new SoftBevelBorder(BevelBorder.LOWERED));
            add(notice);
        }    // 增加显示格。在添加到Container之前,设置其Border。
        public void addIndicator(JComponent comp) {
            comp.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));        // 按默认的添加方式,显示格会挤在一起,所以之间填充一个水平的刚性支撑。
            add(Box.createRigidArea(XGAP));
            add(comp);
        }
    }
      

  2.   

    http://blog.csdn.net/UnAgain/category/186311.aspx
      

  3.   

    帮忙顶一下
    http://community.csdn.net/Expert/topic/4683/4683929.xml?temp=.3225672