You can add MouseListener to the components an manually adjust the divider location.
Here is a basic example to get you started:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DividerListener extends MouseAdapter
{
private JSplitPane splitPane;
private Component component;
private int pressedX;
private int dividerLocation;
public DividerListener(JSplitPane splitPane, Component component)
{
this.splitPane = splitPane;
this.component = component;
component.addMouseListener(this);
component.addMouseMotionListener(this);
}
@Override
public void mousePressed(MouseEvent e)
{
pressedX = SwingUtilities.convertPoint(component, e.getPoint(), splitPane).x;
dividerLocation = splitPane.getDividerLocation();
}
@Override
public void mouseDragged(MouseEvent e)
{
int draggedX = SwingUtilities.convertPoint(component, e.getPoint(), splitPane).x;
int deltaX = draggedX - pressedX;
splitPane.setDividerLocation(dividerLocation + deltaX);
}
private static void createAndShowGUI()
{
JSplitPane splitPane = new JSplitPane();
JLabel left = new JLabel("LEFT");
splitPane.setLeftComponent(left);
new DividerListener(splitPane, left);
JLabel right = new JLabel("RIGHT");
splitPane.setRightComponent(right);
new DividerListener(splitPane, right);
JFrame frame = new JFrame("SSCCE");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add( splitPane);
frame.setLocationByPlatform( true );
frame.setSize(200, 200);
frame.setVisible( true );
}
public static void main(String[] args)
{
EventQueue.invokeLater( () -> createAndShowGUI() );
/*
EventQueue.invokeLater(new Runnable()
{
public void run()
{
createAndShowGUI();
}
});
*/
}
}
You will need to customize the logic to check if the mouse is pressed at the right edge of the left component or the left edge of the right component. So you will probably need to add another parameter so you know how to do the bounds checking.
Then you would need to set a flag so the mouseDragged code can either process the event or ignore it when you are not close enough to the edge.