I spent quite a bit of time trying to get to the point of having a
SSCCE but was unable to do so
.
EDIT_1st.
The left side of the JSplitPane is a JTabbedPane with a number of tabs
- a very complex layout. When the left side reaches a certain level of complexity, dragging the divider to move the divider location no
longer works, but I can still move the divider by explicitly setting
the location.
Distributing Space When a JSplitPane Container Is Resized The weight
of a split pane controls the behavior of the divider when the split
pane is resized. If the weight is 0, all extra space is given to the
right or bottom component. If the weight is 1, all extra space is
given to the left or top component. A weight of .3 specifies that the
left or top component gets one-third of the extra space. The weight
also determines how the children lose space when the size of the split
pane is reduced. For example, a weight of 0 means that the left or top
component does not lose any space.
The weight also controls the starting location of the divider. For
example, if the weight is .5, the divider is placed in the center.
COPY
// Create a left-right split pane
JSplitPane pane = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent);
// Get current weight
double weight = pane.getResizeWeight(); // 0.0 by default
// Keep the size of the right component constant
weight = 1D;
pane.setResizeWeight(weight);
// Split the space evenly
weight = .5D;
pane.setResizeWeight(weight);
EDIT_2nd.
you forgot to tell us that in Nimbus is there awfull flickering with divider, not caused with rest of Standard L&Fs
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
public class JSplitPaneToy {
private JSplitPane sp;
public JSplitPaneToy() {
sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, makePanel(), makePanel());
/*SplitPaneUI ui = sp.getUI();
if (ui instanceof BasicSplitPaneUI) {
((BasicSplitPaneUI) ui).getDivider().setBorder(null);
}*/
BasicSplitPaneUI l_ui = (BasicSplitPaneUI) sp.getUI();
BasicSplitPaneDivider l_divider = l_ui.getDivider();
l_divider.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
Dimension l_pane_size = sp.getSize();
if (sp.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
int l_new_loc = sp.getDividerLocation() + e.getX();
if (l_new_loc >= 0 && l_new_loc <= l_pane_size.width) {
sp.setDividerLocation(l_new_loc);
}
} else {
int l_new_loc = sp.getDividerLocation() + e.getY();
if (l_new_loc >= 0 && l_new_loc <= l_pane_size.height) {
sp.setDividerLocation(l_new_loc);
}
}
}
});
sp.setBorder(BorderFactory.createEmptyBorder());
/*sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, makePanel(), sp);
ui = sp.getUI();
if (ui instanceof BasicSplitPaneUI) {
((BasicSplitPaneUI) ui).getDivider().setBorder(null);
}
sp.setBorder(BorderFactory.createEmptyBorder());
sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, makePanel(), sp);
ui = sp.getUI();
if (ui instanceof BasicSplitPaneUI) {
((BasicSplitPaneUI) ui).getDivider().setBorder(null);
}
sp.setBorder(BorderFactory.createEmptyBorder());
sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, makePanel(), sp);
ui = sp.getUI();
if (ui instanceof BasicSplitPaneUI) {
((BasicSplitPaneUI) ui).getDivider().setBorder(null);
}
sp.setBorder(BorderFactory.createEmptyBorder());*/
JFrame frame = new JFrame("JSplitPane Toy");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(sp);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new JSplitPaneToy();
}
});
}
private JScrollPane makePanel() {
JScrollPane pane = new JScrollPane(new JTable(
new Object[][]{{0, 1, 2}, {1, 2, 3}, {2, 3, 4}}, new Object[]{1, 2, 3}) {
});
pane.setPreferredSize(new Dimension(200, 100));
return pane;
}
}