简体   繁体   English

Java - 内置边距和JTextArea的JPanel

[英]Java - JPanel with margins and JTextArea inside

I want to create something like this: 我想创建这样的东西:

居中的文字区域

Main panel has its margins (x), and TextArea in the center of that panel which almost fills up the panel. 主面板的边距(x)和TextArea位于该面板的中心,几乎填满了面板。 At the bottom is another panel with custom size (height y), which can be toggled visible and unvisible with some shortcut. 在底部是另一个具有自定义大小(高度y)的面板,可以通过一些快捷方式切换为可见和不可见。 Bottom Panel has FlowLayout and few elements. 底部面板具有FlowLayout和少量元素。

The problem is I have no idea how to do this. 问题是我不知道该怎么做。

BoxLayout has no margins. BoxLayout没有边距。

I tried with GridBagLayout but I doesn't work or I can't understand it enough :( 我尝试使用GridBagLayout,但我不工作或我不能理解它:(

I tried also with setting JTextArea margins 我也试过设置JTextArea边距

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

but when there is a lot of text, top and bottom margin disappear. 但是当有大量文字时,顶部和底部边距消失。 So now I'm trying with Panels. 所以现在我正在尝试使用Panels。

Can someone help me with this please? 请有人帮我这个吗?

there are two ways 有两种方法

easiest way would be use EmptyBorders 最简单的方法是使用EmptyBorders

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM