我正在从事一个计算机科学项目,我遇到了一些边框布局问题: 这是我的配置(简化)
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"));
}
}
现在,我的项目不同了,但这是我的配置
当我运行主程序(一个带有 JTabbed 的 jframe,并将其作为选项卡附加)时,它只向我显示中心而不是最后一个。但如果我在开始时附加 PEnd,它就会按照必须的方式播种。
编辑 14-3-14 我深入研究了我的代码,发现问题是由 myTable 的滚动 Pane 生成的,因此删除它将使 PEnd 显示,但 mytable 以可怕的方式表示自己
最佳答案
PEnd,您在 PAGE_END
添加的面板未添加任何内容,因此没有任何内容可显示,并且大小为 0。
也许用线
pend.add(new JButton("Store"));
你的意思是
PEnd.add(new JButton("Store"));
顺便说一句,变量名应该以小写开头,以遵循标准 Java 风格,以便将它们与类区分开来。
关于Java BorderLayout,南永远不会显示自己,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22386924/