将JPanel大小设置为以较小的边距填充父级 [英] Set the JPanel size to fill parent with little margin

查看:491
本文介绍了将JPanel大小设置为以较小的边距填充父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Jpanel( JpanelLeft JpanelLeftContent )如何使JpanelLeftContent填充父级大小,左侧和右侧有一点边距。我尝试了不同的布局,并试图修改hgap和vgap值,但没有一个给我一个好的结果。

  JPanel JpanelLeft = new JPanel(); 
JPanel JpanelLeftContent = new JPanel();
JpanelLeft.add(JpanelLeftContent);

如果可能的话,我如何使JpanelLeftContent看起来像一个圆角矩形,如图所示。 / p>

解决方案

看一下 Border 的工作方式。特别是 BorderFactory.createEmptyBorder(int top,int left,int bottom,int right) 可能会有所帮助。


I have two Jpanel (JpanelLeft and JpanelLeftContent) how can i make the JpanelLeftContent fill parent size with a little margin on the left an right side. i have tried different layout and tried to modify the hgap and vgap values, but none of them give me a good result.

  JPanel JpanelLeft = new JPanel();
  JPanel JpanelLeftContent = new JPanel();
  JpanelLeft.add(JpanelLeftContent);

And if possible how can i make the JpanelLeftContent look like a rounded rectangle as shown in the picture.

解决方案

Take a look at how Borders work. Especially
BorderFactory.createEmptyBorder(int top, int left, int bottom, int right) might be helpfull.

这篇关于将JPanel大小设置为以较小的边距填充父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆