Java: Problem with JSplitpane?

I think your problem is that you add a component twice (that could really make thinks look strange). E. G you do something like: split.

SetLeftComponent(split. GetRightComponent()) So when you do the swap you need to remove the components first: private static void swap(JSplitPane split) { Component r = split. GetRightComponent(); Component l = split.

GetLeftComponent(); // remove the components split. SetLeftComponent(null); split. SetRightComponent(null); // add them swapped split.

SetLeftComponent(r); split. SetRightComponent(l); } And the demo is here (also moves the divider location): public static void main(String args) { JFrame frame = new JFrame("Test"); final JSplitPane split = new JSplitPane( JSplitPane. HORIZONTAL_SPLIT, new JLabel("first"), new JLabel("second")); frame.

Add(split, BorderLayout. CENTER); frame. Add(new JButton(new AbstractAction("Swap") { @Override public void actionPerformed(ActionEvent e) { // get the state of the devider int location = split.

GetDividerLocation(); // do the swap swap(split); // update the devider split. SetDividerLocation(split.getWidth() - location - split.getDividerSize()); } }), BorderLayout. SOUTH); frame.

SetDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); frame. SetSize(400, 300); frame.

SetVisible(true); }.

I think your problem is that you add a component twice (that could really make thinks look strange). E. G you do something like: split.

SetLeftComponent(split. GetRightComponent()). So when you do the swap you need to remove the components first: private static void swap(JSplitPane split) { Component r = split.

GetRightComponent(); Component l = split. GetLeftComponent(); // remove the components split. SetLeftComponent(null); split.

SetRightComponent(null); // add them swapped split. SetLeftComponent(r); split. SetRightComponent(l); } And the demo is here (also moves the divider location): public static void main(String args) { JFrame frame = new JFrame("Test"); final JSplitPane split = new JSplitPane( JSplitPane.

HORIZONTAL_SPLIT, new JLabel("first"), new JLabel("second")); frame. Add(split, BorderLayout. CENTER); frame.

Add(new JButton(new AbstractAction("Swap") { @Override public void actionPerformed(ActionEvent e) { // get the state of the devider int location = split. GetDividerLocation(); // do the swap swap(split); // update the devider split. SetDividerLocation(split.getWidth() - location - split.getDividerSize()); } }), BorderLayout.

SOUTH); frame. SetDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); frame.

SetSize(400, 300); frame. SetVisible(true); }.

Exactly... this code : GUI6. Gui6. JSplitPane1.

SetRightComponent(null); GUI6. Gui6. JSplitPane1.

SetLeftComponent(null); was the key of problem. I tried method removeAll() before. But this is the best way.

Thank you so much! – sajad Feb 2 at 8:20 No problem! :):) – dacwe Feb 2 at 8:30.

I would like to have a jsplitPane and swap right component by left component while running my program. I set division location about 0.2. When I swapped my left component and right component and set division location about 0.8; there is a problem with jSplitPane.

It is locked and I can't move divisor. Also after that; when I try to assign another component to right or left side of JSplitPane, the components appear bollixed. I tried by setDivisionLocation() method before swapping right and left component; but it is not effective.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions