SIze of Jpanel inside JSplitPanel

nik123

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?

UmFraWJ1bCBJc2xhbQ

I was trying to add JsplitPane into my project.Requirement is i need to add two Jpanel inside right panel of JSplitPane.

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

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:

https://community.oracle.com/docs/DOC-983539

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related