Link to home
Start Free TrialLog in
Avatar of ajayjain
ajayjain

asked on

how can i use 2 splitpanes with 3 components

dear,
 
i want to use 2 SplitPanes for spliting 3 components at a time . The code will make it more clear.

ScrollPane1,ScrollPane2,ScrollPane3 are 3 scrollPanes having 3 components added to it.

sp1,sp2 are 2 SplitPanes.
panel is JPanel.

/* code*/
 
sp1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollPane,scrollPane1);
sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollPane1,scrollPane2);
panel1.add(sp1);
panel2.add(sp2);

Means i need to share scrollPane1 between 2 SplitPanes.

PROBLEM OCCURING : 2 SplitPanes are appered properly but only 1 is enabled which is added later i.e. splitPane2.

please give me the appropriate suggetions.
thanx in Advance

regards
AJAY JAIN



Avatar of Ovi
Ovi

Yes, that's the normal behaviour. You cannot add a component in two different locations on the screen (application). Use cloned scrollPane or another one synchronized with the original.
Avatar of ajayjain

ASKER

Ya that's okkai.

To sove this problem wt i did is :

i added the mouse LIstener to both these  SplitPanes.So that if i m using 1st splitPane then i must remove the scrollPane 1 from another SplitPane. and vise versa .

Means i dynamically trying to use scrollPane1 with both the SplitPane.

PROBLEM OCCURING : The mouse click event not able to detect the devider .

is there any way so that i could know which SplitPane devider is in use currently .

regards

AJAY JAIN
The scrollPane and the holding splitpane will not receive mouse events because the events will be captured by the component contained by the scrollPane. You couls trick this if you will use something like this:

1. create a JPanel called scrollPaneHolder
2. set the layout to BorderLayout
3. Add to north a JLabel called titleLabel
4. Add to center the scrollPane

You will have as result a component which looks like a window, and you can use the JLabel (title), as mouseEvent notification component. When you click on the "window" in the left side, you will move the scrollPane from the right scrollPaneHolder. When you click on right you'll move'it from left. You could set some active/innactive collors to the JLabel and so you'll make a pretty intuitive and user friendly component.

Hope it will help you.
Avatar of Mick Barry
> ScrollPane1,ScrollPane2,ScrollPane3 are 3 scrollPanes having 3 components added to it.

What happended to ScrollPane3??
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
heyyy thanx "object"
Your idea  working.

regards
AJAY JAIN
good to hear :)