Java - JPanel with margins and JTextArea inside

吃可爱长大的小学妹 提交于 2019-12-21 07:16:33

问题


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. 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?


回答1:


there are two ways

  • use propers Borders, in this case EmptyBorders

  • use proper LayoutManager, BorderLayout(int horizontalGap, int verticalGap), GridLayout(int rows, int cols, int hgap, int vgap),

easiest way would be use EmptyBorders



来源:https://stackoverflow.com/questions/9565760/java-jpanel-with-margins-and-jtextarea-inside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!