如何阻止BorderLayout的中心向东和向西移动? [英] How do I stop center of BorderLayout from taking up east and west?
本文介绍了如何阻止BorderLayout的中心向东和向西移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个程序,其中使用BorderLayout
,尽管CENTER
是一个位置,但EAST
和WEST
位置并未填充.结果,中心部分扩展到了东西两个部分所在的空间.
I have a program in which I use BorderLayout
and the EAST
and WEST
positions are not filled, though the CENTER
one is. As a result, the center component extends to the space where the east and west components would be.
如何防止这种情况?我知道我可以在东方和西方位置使用空白的JPanel
,但这似乎很麻烦.
How can I prevent this? I know I could just use a blank JPanel
in the east and west positions, but that seems hacky.
推荐答案
如果您想要的是中央面板周围的空白区域,则可以为其添加边框:
If what you want is empty space around your center panel, you can add a border to it:
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10);
这篇关于如何阻止BorderLayout的中心向东和向西移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文