Java - JPanel with margins and JTextArea inside
Asked Answered
G

1

13

I want to create something like this:

Centered text area

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 has no margins.

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

I tried also with setting JTextArea margins

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.

Can someone help me with this please?

Grodno answered 5/3, 2012 at 11:21 Comment(0)
P
19

there are two ways

easiest way would be use EmptyBorders

Prelusive answered 5/3, 2012 at 11:30 Comment(3)
mKorbel thank you! I used matteBorder around Panel with the same color as JTextArea.Grodno
glad to help you +1 for questionPrelusive
The separate objectification of something as primitive as a margin (EmptyBorders) made me laugh and cry at the same time. Your answer solved my problem though, so all is well in the end :-)Racemose

© 2022 - 2024 — McMap. All rights reserved.