Java - 内置边距和JTextArea的JPanel [英] Java - JPanel with margins and JTextArea inside

查看:1160
本文介绍了Java - 内置边距和JTextArea的JPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建这样的东西:

主面板的边距(x)和TextArea位于该面板的中心,几乎填满了面板。
底部是另一个具有自定义尺寸(高度y)的面板,可以通过一些快捷方式切换为可见和不可见。底部面板有FlowLayout和几个元素。

Main panel has its margins (x), and TextArea in the center of that panel which almost fills up the panel. At the bottom is another panel with custom size (height y), which can be toggled visible and unvisible with some shortcut. Bottom Panel has FlowLayout and few elements.

问题是我不知道如何做到这一点。

The problem is I have no idea how to do this.

BoxLayout没有边距。

BoxLayout has no margins.

我尝试使用GridBagLayout但我没有工作或者我不能理解它:(

I tried with GridBagLayout but I doesn't work or I can't understand it enough :(

我也试过设置JTextArea边距

I tried also with setting JTextArea margins

textMain.setMargin(new Insets(insetTop, insetLeft, insetBottom, insetRight));

但是当有大量文字时,顶部和底部边距消失。所以现在我我正在尝试使用Panels。

but when there is a lot of text, top and bottom margin disappear. So now I'm trying with Panels.

有人可以帮我这个吗?

推荐答案

有两种方式

使用正确的 LayoutManager BorderLayout(int horizo​​ntalGap,int verticalGap) GridLayout(int rows,int cols,int hgap,int vgap)

最简单的方法是使用 EmptyBorders

这篇关于Java - 内置边距和JTextArea的JPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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