我已经制作了一个面板(它是一排按钮),并将它放在框架的底部(南),但我想在它下面添加两行(面板/子面板)(一个文本输入线和输出线,如果重要的话)。现在我唯一知道要做的就是声明并添加更多面板,这很好,但是当我指定 .SOUTH 时,它们会越过前一个面板。
编辑:我使用的解决方案
按照 Ted Hopp 的建议,我将我的原始面板(现在称为 subPanel1)以及在原始面板(subPanel2 和 subPanel3)之上的两个新面板添加到第四个“容器面板”(bottomCotainerPanel) ).因为我只有三个子面板,所以我可以指定每个子面板在 containerPanel 中的位置(使用 NORTH、CENTER、SOUTH,如果超过 3 个,可能需要做一些稍微不同的事情……),然后指定位置contianerPanel 将进入框架(南)。
subPanel1.setLayout(new GridLayout(1,6)); //Layout of subPanel1
subPanel1.add(clearButton);
subPanel1.add(customerNameLabel);
subPanel1.add(customerNameTextField);
subPanel1.add(showByNameButton);
subPanel1.add(openNewSavingsButton);
subPanel1.add(openNewCheckingButton);
subPanel2.add(sendChatTextField);
subPanel2.add(sendButton);
subPanel2.add(clearButton2);
subPanel3.add(receiveChatTextField);
subPanel3.add(nextButton);
subPanel3.add(previousButton);
bottomContainerPanel.setLayout(new GridLayout(3,1)); //Layout of Container Panel
bottomContainerPanel.add(subPanel1, BorderLayout.NORTH);
bottomContainerPanel.add(subPanel2, BorderLayout.CENTER);
bottomContainerPanel.add(subPanel3, BorderLayout.SOUTH);
tellerWindow.getContentPane().add(bottomContainerPanel, BorderLayout.SOUTH);
最佳答案
您需要添加一个容器面板作为框架的南面板。对于底部的所有内容,容器本身应该具有您想要的布局。
关于java - 如何将面板拆分为子面板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13126979/