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?
I was trying to add
JsplitPane
into my project.Requirement is i need to add twoJpanel
inside right panel ofJSplitPane
.
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 that JSplitPane
, say in our case Right, it is better to use Nesting Split Panes. That means creating Split Panes inside Split Panes.
so what i had done is first add
Jpanel
say itpanel1
to right panel and setBoxLayout.Y-AXIS
and than add two panel insidepanel1
.now in that two panel first panel have
BoxLayout
and i want the width of this panel to be of size ofpanel1
but i am not able to do it.
If you use Nesting Split Panes, you may not have to create an extra Parent JPanel
what you said as panel1
. 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 as panel1
and then put your two child panels inside the two Panes created by new JSplitPane
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:
private JSplitPane jSplitPane1;
private JSplitPane jSplitPane2;
private JPanel jPanel1;
private JPanel jPanel2;
In Constructor:
jSplitPane1 = new JSplitPane();
jSplitPane2 = new JSplitPane();
jSplitPane1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
jSplitPane1.setRightComponent(jSplitPane2);
jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
jSplitPane1.setTopComponent(jPanel1);
jSplitPane1.setBottomComponent(jPanel2);
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: