I have two panels , one is JTree
in a JScrollPane
and the other is JTable
in a JScrollPane
. How can I place them in adjacent position using the JSplitPane.TOP
and JSplitPane.BOTTOM
constants so that they must equal space in the main panel?
Asked
Active
Viewed 120 times
-1

Ansharja
- 1,237
- 1
- 14
- 37

L.Sankaranarayanan
- 1
- 1
- 1
1 Answers
0
By using a JSplitPane
, you can place one component above the other with JSplitPane.VERTICAL_SPLIT
. Create your split pane like below:
splitPane = new JSplitPane (JSplitPane.VERTICAL_SPLIT, jtreeScrollPane, jtableScrollPane);
If you want to give them the same space, you can use:
splitPane.setResizeWeight (0.5);
Check the How to Use Split Panes official tutorial for details.
You can also set a GridLayout
as your mainpanel's
layout in order to give your scrollpanes the same size.
If you want to put your scrollpanes one above the other you can set 2 rows and 1 column, if you want to align them horizontally you can use 1 row and 2 columns.
See the How to use GridLayout tutorial for further details.

Ansharja
- 1,237
- 1
- 14
- 37
-
I have tried it. It didnt work. Finally I found one from a code segment – L.Sankaranarayanan Dec 23 '17 at 18:50