下面是源码,哪位大大帮我搞定,100分相送.
//MainFrame.java
package yagumo.PeiGet;import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.plaf.*;public class MainFrame extends JFrame {
    public MainFrame() {
        try {
            jbInit();
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
    }    private void jbInit() throws Exception {
        getContentPane().setLayout(borderLayout);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setUIFont(globalFont);
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        SwingUtilities.updateComponentTreeUI(this.getContentPane());
        getContentPane().add(new DownLoadPanel(this), BorderLayout.CENTER);
        pack();
        Toolkit toolKit = Toolkit.getDefaultToolkit();
        setLocation((toolKit.getScreenSize().width - getSize().width) / 2,
                    (toolKit.getScreenSize().height - getSize().height) / 2);
    }    public static void main(String[] args) {
        MainFrame mainFrame = new MainFrame();
        mainFrame.show();
    }    public void setUIFont(javax.swing.plaf.FontUIResource font) {
        java.util.Enumeration keys = UIManager.getLookAndFeelDefaults().keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof javax.swing.plaf.FontUIResource)
                UIManager.put(key, font);
        }
    }    BorderLayout borderLayout = new BorderLayout();
    FontUIResource globalFont =new FontUIResource("宋体",Font.PLAIN,12);
}

解决方案 »

  1.   

    //DownLoadPanel.javapackage yagumo.PeiGet;import java.awt.*;
    import javax.swing.*;
    import java.awt.Dimension;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.*;
    import javax.swing.table.*;public class DownLoadPanel extends JPanel {
        public JTree jTreePath = getJTreePath();
        public JTable jTableTask1 = getJTableTask();
        public JTable jTableTask2 = getJTableTask();
        public JTable jTableTask3 = getJTableTask();
        public DownLoadPanel(JFrame jFrame) {
            try {
                jbInit();
            }
            catch (Exception exception) {
                exception.printStackTrace();
            }
        }    private void jbInit() throws Exception {
            JScrollPane jScrollPane1 = new JScrollPane(jTreePath);
            jTreePath.setPreferredSize(new Dimension(200, 400));
            JScrollPane jScrollPane2 = new JScrollPane(jTableTask1);
            jTableTask1.setPreferredSize(new Dimension(400, 200));
            JScrollPane jScrollPane3 = new JScrollPane(jTableTask2);
            jTableTask2.setPreferredSize(new Dimension(200, 200));
            JScrollPane jScrollPane4 = new JScrollPane(jTableTask3);
            jTableTask3.setPreferredSize(new Dimension(200, 200));
            JSplitPane jSplitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            JSplitPane jSplitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
            JSplitPane jSplitPane3 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            jSplitPane3.setLeftComponent(jScrollPane3);
            jSplitPane3.setRightComponent(jScrollPane4);
            jSplitPane2.setTopComponent(jScrollPane2);
            jSplitPane2.setBottomComponent(jSplitPane3);
            jSplitPane1.setLeftComponent(jScrollPane1);
            jSplitPane1.setRightComponent(jSplitPane2);
            
            this.add(jSplitPane1);
        }    /**
         * 生成JTreePath树型结构
         * @return JTree
         */
        private JTree getJTreePath() {
            DefaultMutableTreeNode nodeTop = new DefaultMutableTreeNode("PeiGet");
            DefaultMutableTreeNode nodeDownloading = new DefaultMutableTreeNode("正在下载");
            nodeTop.add(nodeDownloading);
            DefaultMutableTreeNode nodeDownloaded = new DefaultMutableTreeNode("已下载");
            DefaultMutableTreeNode nodeSoftware = new DefaultMutableTreeNode("软件");
            nodeDownloaded.add(nodeSoftware);
            DefaultMutableTreeNode nodeGame = new DefaultMutableTreeNode("游戏");
            nodeDownloaded.add(nodeGame);
            nodeTop.add(nodeDownloaded);
            DefaultMutableTreeNode nodeDeleted = new DefaultMutableTreeNode("已删除");
            nodeTop.add(nodeDeleted);        JTree jTree = new JTree(nodeTop);
            jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
            return jTree;
        }    private JTable getJTableTask() {
            String[] colName = {"文件名","地址"};
            String[][] data = {{"file1", "http://yagumo.com/"},
                               {"file2", "http://yagumo.com/"}};
            JTable jTable = new JTable(data, colName);
            jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            jTable.setPreferredScrollableViewportSize(new Dimension(200, 200));
            return jTable;
        }
    }
      

  2.   

    thats the limitation of borderlayout.
    when you change the frame size, only the side component of the border layout( north, south, east, west) will adjust their size accordingly. the central component will not change.
      

  3.   

    To: midlet(midlet)
    那么我应该怎么办呢?我用borderlayout是因为想在north上放工具条,south上放状态栏,中间实际上east,west对我来说没什么用.
      

  4.   

    To: midlet(midlet)
    做了一个测试,和你的说明不一样,改变窗体尺寸,注意中间button大小.import java.awt.*;
    import javax.swing.*;
    import java.awt.BorderLayout;public class TestBL extends JFrame {
        BorderLayout borderLayout1 = new BorderLayout();
        JButton jButton1 = new JButton();
        JButton jButton2 = new JButton();
        JButton jButton3 = new JButton();
        JButton jButton4 = new JButton();
        JButton jButton5 = new JButton();
        public TestBL() {
            try {
                jbInit();
            }
            catch (Exception exception) {
                exception.printStackTrace();
            }
        }    private void jbInit() throws Exception {
            getContentPane().setLayout(borderLayout1);
            jButton1.setText("jButton1");
            jButton5.setText("jButton5");
            this.getContentPane().add(jButton1, java.awt.BorderLayout.WEST);
            jButton4.setText("jButton4");
            jButton3.setText("jButton3");
            this.getContentPane().add(jButton2, java.awt.BorderLayout.NORTH);
            this.getContentPane().add(jButton4, java.awt.BorderLayout.SOUTH);
            this.getContentPane().add(jButton3, java.awt.BorderLayout.EAST);
            this.getContentPane().add(jButton5, java.awt.BorderLayout.CENTER);
            jButton2.setText("jButton2");
        }    public static void main(String[] args) {
            TestBL testbl = new TestBL();
            testbl.pack();
            testbl.show();
        }
    }
      

  5.   

    sorry yagumo, i think i remember it wrongly.It should that the center component changes size while the rest keep fixed.
    The east and west components will change their width, and the north south will not change their height.
      

  6.   

    hi yagumo, its better you  leave the layout manager to set the size of different components instead of setting preferred size for each component manully.
      

  7.   

    PreferredSize实际上没有影响,我试过把全部的setPreferredSize语句注释掉,结果一样.
    So I think it's not the key point to my problem. If I added JSplitPane into JFrame directly, not using JPanel as a mid-layer, it would be worked well. but, It's not what I expected. For some reason, I have to put JFrame and components in it into different class, so I need a JPanel to contain this components.
    好久没说鸟语了,哈哈哈,有点痛快.
      

  8.   

    外面再套一层JPanel如何,把他的layout设置为BorderLayout(),在把东西放进panel中    private void jbInit() throws Exception {
            JPanel pane1=new JPanel();
            pane1.setLayout(new BorderLayout());
            pane1.add(jTreePath,BorderLayout.CENTER);
            JScrollPane jScrollPane1 = new JScrollPane(pane1);
            jTreePath.setPreferredSize(new Dimension(200, 400));
            JPanel pane2=new JPanel();
            pane2.setLayout(new BorderLayout());
            pane2.add(jTableTask1,BorderLayout.CENTER);
            JScrollPane jScrollPane2 = new JScrollPane(pane2);
            jTableTask1.setPreferredSize(new Dimension(400, 200));        JPanel pane3=new JPanel();
            pane3.setLayout(new BorderLayout());
            pane3.add(jTableTask2,BorderLayout.CENTER);
            JScrollPane jScrollPane3 = new JScrollPane(pane3);
            jTableTask2.setPreferredSize(new Dimension(200, 200));        
            JPanel pane4=new JPanel();
            pane4.setLayout(new BorderLayout());
            pane4.add(jTableTask3,BorderLayout.CENTER);
            JScrollPane jScrollPane4 = new JScrollPane(pane4);
            jTableTask3.setPreferredSize(new Dimension(200, 200));        JSplitPane jSplitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            JSplitPane jSplitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
            JSplitPane jSplitPane3 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);        jSplitPane3.setLeftComponent(jScrollPane3);
            jSplitPane3.setRightComponent(jScrollPane4);
            jSplitPane2.setTopComponent(jScrollPane2);
            jSplitPane2.setBottomComponent(jSplitPane3);
            jSplitPane1.setLeftComponent(jScrollPane1);
            jSplitPane1.setRightComponent(jSplitPane2);
            
            this.add(jSplitPane1);
        }
      

  9.   

    另外,你的DownLoadPanel 是个JPanel
    JPanel的默认layout是 FlowLayout,FlowLayout是不会自动让component朝两边扩展的,在this.add(jSplitPanel)前加
    this.setLayout(new BorderLayout());
      

  10.   

    是这样的呀,但是我怎么知道JPanel的默认layout是什么呢,jdkdoc上面好象没说呀,JFrame的默认是什么呢?
      

  11.   

    表5.1
    ------------------------------------------------------------------------
    组件                                         缺省布局管理器
    ------------------------------------------------------------------------
    JPanel                                       FlowLayout
    JFrame                                       BorderLayout
    JDialog                                      BorderLayout
    JApplet                                      BorderLayout
    Box                                          BoxLayout
    -------------------------------------------------------------------------
      

  12.   

    好,我总结一哈问题所在,然后结贴.
    1.FlowLayout布局在外部容器缩放时其里面的控件不会向两边扩展.
    2.JPanel与其它多数容器不同,默认布局方式是FlowLayout.To: didoleo(冷月无声)
    你把上面的表5.1贴一次到这里
    http://community.csdn.net/Expert/TopicView1.asp?id=3866225
    给你结分,免得被管理员删掉了.结贴.