代码之家  ›  专栏  ›  技术社区  ›  DDS

Java BorderLayout,south从不显示自己

  •  0
  • DDS  · 技术社区  · 11 年前

    我正在做一个计算机科学项目,我对边界布局有一些问题: 这是我的配置(简化)

    public class MainPanel extends JPanel{
        JSplitPane Pcenter;
        JPanel PEnd;
    
        public MainPanel(Container dad){
            JTable myTable=new JTable(), anotherTable=new JTable();
    
            JSplitPane left=new JSplitPane();
            left.setTopComponent(new JScrollPane (myTable));
            left.setBottomComponeny(new JScrollPane(anotherTable));
            left.setOrientation(JSplitPane.VERTICAL_SPLIT);
    
            this.setLayout(new BorderLayout());
            Pcenter=new JSplitPane();
            PEnd=new JPanel();
    
            pend.add(new JButton("Store"));
            Pcenter.setLeftComponent(left);
            Pcenter.setRightComponent(new JScrollpane(new JLabel("right")));
    
            this.add(Pcenter,BorderLayout.CENTER);
            this.add(PPnd,BorderLayout.PAGE_END);
            //EDIT:
            PEnd.add(new JLabel("goofy"));
        }
    }
    

    现在,我的项目不同了,但这是我的配置

    当我运行main(一个jframe,带有一个JTabbed,并将其作为标签)时,它只显示了中心,而不是末端。但如果我在一开始就附上PEnd,它就必须播种。

    编辑14-3-14 我深入研究了我的代码,我发现问题是由myTable的滚动窗格生成的,因此删除它将使PEnd显示出来,但myTable以可怕的方式表示自己

    1 回复  |  直到 11 年前
        1
  •  2
  •   DSquare    11 年前

    PEnd,您正在添加的面板 PAGE_END 没有添加任何内容,因此没有要显示的内容,大小为0。

    也许用这条线

    pend.add(new JButton("Store"));
    

    你的意思是

    PEnd.add(new JButton("Store"));
    

    作为补充说明,变量名应该以小写字母开头,以遵循标准Java风格,以区别于类。