I was trying to add JsplitPane
into my project.Requirement is i need to add two Jpanel
inside right panel of JSplitPane
.
so what i had done is first add Jpanel
say it panel1
to right panel and set BoxLayout.Y-AXIS
and than add two panel inside panel1
.
now in that two panel first panel have BoxLayout
and i want the width of this panel to be of size of panel1
but i am not able to do it.
anyone have idea how to do it?
When using
JSplitPane
, we should remember that it only divides the pane into two components say Left and Right or Top and Bottom. So when we again want to add more than one components in a single side of thatJSplitPane
, say in our case Right, it is better to use Nesting Split Panes. That means creating Split Panes inside Split Panes.If you use Nesting Split Panes, you may not have to create an extra Parent
JPanel
what you said aspanel1
. Actually the Split Pane is used to divide the Pane into two segments. So, by using Nesting Split Panes you are creating another Split Pane in stead of what you were creating aspanel1
and then put your two child panels inside the two Panes created by newJSplitPane
which is nested. So, you don't have to think about the size issue, too. I hope I could make you clear and it solved your issue.A simple way to achieve that by using:
Declaration:
In Constructor:
The above described method is the simplest to achieve what you wanted. However, without nesting the Split Pane, it is possible to use Multi Split Panes which may not be so handy. Still you can have a look at this old article at Oracle:
https://community.oracle.com/docs/DOC-983539