JSplitPane divider not movable

What would prevent a JSplitPane divider from being movable in its initial state?
The left pane contains a JTabbedPane, and the right pane contains a JPanel. When the app starts, the left pane is as wide as a single tab, and the divider cannot be dragged. If I click the right arrow on the divider, it expands to the right and then I can drag it.
I don't observe this behavior in the JSplitPane examples in the tutorials. I figure it must be something about the pane contents that triggers this. But what?
Braden

make sure you set the min, max, and preferredsize of both sides of the splitpane

Similar Messages

  • JSplitPane divider (One touch expandable)

    Hi all,
    I am having some problems with the JSplitPane divider. I am using onetouch expandable.
    I want to stop the divider moving all the way up to the top of the window when the up arrow is clicked on. When you drag the divider up it stops near the top but doesn't go all the way up. but click on the up arrow on the divider bar and it rises completely to the top. How can I stop this from happening.
    I have managed to add an action listener to the buttons on the divider bar, In the action listener I do the following - splitPane.setDividerLocation(0.1);
    splitPane.updateUI();
    This works but then an exception is thrown -
    Exception occurred during event dispatching:
    java.lang.NullPointerException
         at javax.swing.plaf.basic.BasicSplitPaneDivider$OneTouchActionHandler.actionPerformed(BasicSplitPaneDivider.java:916)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
         at java.awt.Component.processMouseEvent(Component.java:3717)
         at java.awt.Component.processEvent(Component.java:3546)
         at java.awt.Container.processEvent(Container.java:1167)
         at java.awt.Component.dispatchEventImpl(Component.java:2595)
         at java.awt.Container.dispatchEventImpl(Container.java:1216)
         at java.awt.Component.dispatchEvent(Component.java:2499)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2458)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2223)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2132)
         at java.awt.Container.dispatchEventImpl(Container.java:1203)
         at java.awt.Window.dispatchEventImpl(Window.java:918)
         at java.awt.Component.dispatchEvent(Component.java:2499)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:134)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:101)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
    Can anyone help me out?
    thanks,
    Paul.

    I have partial solution to the above problem but in doing so have encountered another problem that I can see no solution to. Can anyone help?
    I have a calss that extends BasicSplitPaneDivider and in this calss i overide the OneTouchActionHandler with a version that sets the top value to be the top of the frame + the height of the component I want left shown. My problem is that this code never runs. The origional OneTouchActionHandler in the BasicSplitPaneDivider runs not my version. How can I get my version to run.
    The version in BasicSplitPaneDivider is protected.
    This code never runs.
    <pre>
    * Listeners installed on the one touch expandable buttons.
    public class OneTouchActionHandlernew implements ActionListener {
         /** True indicates the resize should go the minimum (top or left)
         * vs false which indicates the resize should go to the maximum.
         private boolean toMinimum;
         OneTouchActionHandlernew(boolean toMinimum) {
         this.toMinimum = toMinimum;
    public void actionPerformed(ActionEvent e) {
    Insets insets = splitPane.getInsets();
         int lastLoc = splitPane.getLastDividerLocation();
    int currentLoc = splitPaneUI.getDividerLocation(splitPane);
         int newLoc;
         // We use the location from the UI directly, as the location the
         // JSplitPane itself maintains is not necessarly correct.
    System.out.println("The action listener is being used ");
         if (toMinimum) {
              if (orientation == JSplitPane.VERTICAL_SPLIT) {
              if (currentLoc >= (splitPane.getHeight() -
                        insets.bottom - getDividerSize()))
                   newLoc = lastLoc;
              else
                   newLoc = insets.top + 40;
              else {
              if (currentLoc >= (splitPane.getWidth() -
                        insets.right - getDividerSize()))
                   newLoc = lastLoc;
              else
                   newLoc = insets.left;
         else {
              if (orientation == JSplitPane.VERTICAL_SPLIT) {
              if (currentLoc == insets.top)
                   newLoc = lastLoc;
              else
                   newLoc = splitPane.getHeight() - getHeight() -
                   insets.top;
              else {
              if (currentLoc == insets.left)
                   newLoc = lastLoc;
              else
                   newLoc = splitPane.getWidth() - getWidth() -
                   insets.left;
         if (currentLoc != newLoc) {
              splitPane.setDividerLocation(newLoc);
              // We do this in case the dividers notion of the location
              // differs from the real location.
              splitPane.setLastDividerLocation(currentLoc);
    } // End of class BasicSplitPaneDivider.LeftActionListener
    </pre>

  • JSplitPane Divider problem...

    I'm having problem with the JSplitPane divider. Ive learned that the MouseListener class is most likely the reason why the divider isn't performing as expected. I had to learn how to use the MouseListener interface and I've also learned that the divider is an instance of BasicSplitPaneDivider. I've finally got the divider to PARTIALLY work if I only set the following:
    1) setting the setContinuousLayout(true)
    //setting it to false wont work for some reason, I want to fix that, too. By setting it to false, the divider wont move :(.
    and
    2) if I move the mouse slowly, so the divider can follow the mouse. If I move my mouse too fast, then my divider will suddenly stop the moment the mouse cursor hovers away from the divider.
    Can anyone help me fix the divider problem? Thanks in advance! Here's my code below:
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import java.awt.event.MouseEvent;
    import javax.swing.event.MouseInputAdapter;
    import javax.swing.plaf.basic.BasicSplitPaneDivider;
    public class JSplitPaneDemo{
         public static void main(String args[]){
              //Practice p = new Practice("SplitPane Divider Works Now?");
              JSplitPaneDemo x = new JSplitPaneDemo();
              x.new Practice("SplitPane Divider Works Now?");
         public class DendrogramListener extends MouseInputAdapter
              Container contentPane;
              Component button1, button2, button3;
              JSplitPane splitter;
              Point mLocation;
              JFrame myFrame;
              MyGlassPane glass;
              private boolean inDrag = false;
              private boolean inButton = false;
              private boolean inDivider = false;
              public DendrogramListener(JFrame frame)
                   this.myFrame = frame;
                   this.contentPane = frame.getContentPane();
                   this.mLocation = new Point();
              public DendrogramListener(AbstractButton aButton, AbstractButton b2, AbstractButton b3, MyGlassPane glass1, Container cP, JSplitPane split){
                   this.button1 = aButton;
                   this.button2 = b2;
                   this.button3 = b3;
                   this.glass = glass1;
                   this.contentPane = cP;
                   this.mLocation = new Point();
                   this.splitter = split;
              public void mouseDragged(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mouseMoved(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mouseClicked(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mousePressed(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mouseReleased(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
                   inDrag = false;
              public void mouseEntered(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mouseExited(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void redispatchMouseEvent(MouseEvent e){
                   inButton = false;
                   inDrag = false;
                   inDivider = false;
                   Component component = null;
                   JButton tempButton;
                   Container container = contentPane;
                   Point glassPanePoint = e.getPoint();
                   mLocation = e.getPoint();
                   Point containerPoint = SwingUtilities.convertPoint(glass, glassPanePoint, contentPane);
                   int eventID = e.getID();
                 component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y);
                 if (component == null) {
                      //System.out.println("NULL");
                     return;
                 if (component instanceof JButton) {
                     inButton = true;
                 if(component instanceof BasicSplitPaneDivider){
                      inDivider = true;
                      testForDrag(eventID);
                 if (inButton || inDivider)
                           Point componentPoint = SwingUtilities.convertPoint(glass, glassPanePoint, component);
                          component.dispatchEvent(new MouseEvent(component,
                                                               eventID,
                                                               e.getWhen(),
                                                               e.getModifiers(),
                                                               componentPoint.x,
                                                               componentPoint.y,
                                                               e.getClickCount(),
                                                               e.isPopupTrigger()));
                   testForDrag(eventID);
             private void testForDrag(int eventID) {
                 if (eventID == MouseEvent.MOUSE_PRESSED) {
                     inDrag = true;
         public class MyGlassPane extends JComponent {
              int x0, y0;
              Point mLocation;
              public MyGlassPane(AbstractButton aButton, AbstractButton b2, AbstractButton b3, Container cP, JSplitPane splitter){
                   DendrogramListener dl = new DendrogramListener(aButton, b2, b3, this, cP, splitter);
                   addMouseListener(dl);
                   addMouseMotionListener(dl);
             public void setPoint(Point p) {
                 mLocation = p;
         public class Practice extends JFrame implements ActionListener
              private MyGlassPane glassPane;
              public Practice(String str)
                   super(str);
                   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   setDefaultLookAndFeelDecorated(true);
                   addComponents(this);
                   pack();
                   setVisible(true);
              public Practice addComponents(final Practice p)
                   JPanel leftPane = new JPanel();
                   JPanel midPane = new JPanel();
                   JPanel rightPane = new JPanel();
                   JLabel l1 = new JLabel("Left panel");
                   JLabel r1 = new JLabel("Right panel");
                   JLabel m1 = new JLabel("Middle panel");
                   JButton b1 = new JButton("Button 1");
                   JButton b2 = new JButton("Button 2");
                   JButton b3 = new JButton("Button 3");
                   leftPane.add(l1);
                   leftPane.add(b3);
                   b3.setActionCommand("b3");
                   b3.addActionListener(this);
                   leftPane.setPreferredSize(new Dimension(200, 300));
                   midPane.add(m1);
                   midPane.add(b1);
                   midPane.setPreferredSize(new Dimension(200, 300));
                   rightPane.add(r1);
                   rightPane.add(b2);
                   rightPane.setPreferredSize(new Dimension(200, 300));
                   JSplitPane splitter2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, rightPane, midPane);
                   splitter2.setOneTouchExpandable(true);
                   splitter2.setContinuousLayout(true);
                   JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, splitter2);
                   splitter.setOneTouchExpandable(true);
                   splitter.setContinuousLayout(true);
                   getContentPane().add(splitter);
                   glassPane = new MyGlassPane(b1, b2, b3, p.getContentPane(), splitter);
                   this.setGlassPane(glassPane);
                   glassPane.setVisible(true);
                   return p;
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
                   if("b3".equals(arg0.getActionCommand())){
                        JOptionPane.showMessageDialog(this, "Button 3 Pressed!");
    }

    The problem with your listener is that you are only dispatching events to the
    button or divider when the mouse is directly over that component. This results
    in the behavior you see with the divider: you have to move the mouse slowly
    to keep it over the divider otherwise it gets over some other component and
    you stop dispatching the events to it.
    You actually have a similar problem with the buttons: if you click on one, it
    gets the event but if you then drag the mouse out of the button and release
    the mouse, it still triggers the button! This is not how buttons work: if you
    release the mouse when it is not over the button, it shouldn't trigger.
    Try this for your listener:
         public class DendrogramListener extends MouseInputAdapter {
              Component redispatch;
              boolean inside;
              Container contentPane;
              Component button1, button2, button3;
              JSplitPane splitter;
              Point mLocation;
              JFrame myFrame;
              MyGlassPane glass;
              private boolean inDrag = false;
              private boolean inButton = false;
              public DendrogramListener( JFrame frame ) {
                   this.myFrame = frame;
                   this.contentPane = frame.getContentPane();
                   this.mLocation = new Point();
              public DendrogramListener( AbstractButton aButton, AbstractButton b2,
                        AbstractButton b3, MyGlassPane glass1, Container cP,
                        JSplitPane split ) {
                   this.button1 = aButton;
                   this.button2 = b2;
                   this.button3 = b3;
                   this.glass = glass1;
                   this.contentPane = cP;
                   this.mLocation = new Point();
                   this.splitter = split;
              public void mouseDragged( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mouseMoved( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mouseClicked( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mousePressed( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mouseReleased( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
                   inDrag = false;
                   inButton = false;
              public void mouseEntered( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mouseExited( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void redispatchMouseEvent( MouseEvent e ) {
                   int eventID = e.getID();
                   Point glassPanePoint = e.getPoint();
                   Point containerPoint = SwingUtilities.convertPoint( glass, glassPanePoint, contentPane );
                   if ( !inDrag && !inButton && eventID == MouseEvent.MOUSE_PRESSED ) {
                        redispatch = SwingUtilities.getDeepestComponentAt( contentPane, containerPoint.x, containerPoint.y );
                        inButton = ( redispatch instanceof JButton );
                        inside = inButton;
                        if ( !inButton )
                             inDrag = ( redispatch instanceof BasicSplitPaneDivider );
                   if ( inButton || inDrag ) {
                        if ( inButton )
                             eventID = possiblySwitchEventID( eventID, containerPoint );
                        Point componentPoint = SwingUtilities.convertPoint( glass, glassPanePoint, redispatch );
                        redispatch.dispatchEvent( new MouseEvent( redispatch, eventID, e.getWhen(), e.getModifiers(),
                                  componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger() ) );
              private int possiblySwitchEventID( int eventID, Point containerPoint ) {
                   int switchedID = eventID;
                   Component deepest = SwingUtilities.getDeepestComponentAt( contentPane, containerPoint.x, containerPoint.y );
                   if ( deepest == redispatch ) {
                        if ( ! inside )
                             switchedID = MouseEvent.MOUSE_ENTERED;
                        inside = true;
                   } else {
                        if ( inside )
                             switchedID = MouseEvent.MOUSE_EXITED;
                        inside = false;
                   return switchedID;
         }: jay

  • Another JSplitPane divider cursor problem

    I have the same problem discussed elsewhere in that the cursor doesn't change to a E_RESIZE_CURSOR when it's over a split panel divider. The code is in a large application too huge to post, and my attempts to simplify it have been unable to reproduce the problem. I have implemented the solution suggested in [http://forums.sun.com/thread.jspa?forumID=57&threadID=642994] but, although the mouse listener methods are indeed called, the cursor doesn't change. I have also tried calling setCursor on the parent of the JSplitPane, and on the JRootPane, but it doesn't change. In each case the mouse listener is called but the setCursor call has no effect.
    All the discussions on setCursor having no effect I've found are specific to JDialog. In my case, I have a deep window stack starting with JFrame, JRootPane, JLayeredPane, down through several JPanels, a JSplitPane, more JPanels, my JSplitPane, which contains 2 JPanels, and so on.
    What would prevent the JSplitPane divider from changing the cursor itself? Assuming it's trying, just as my explicit mouse listener is, what could be overriding, obscuring, or intercepting my cursor change?
    Any help would be most welcome
    Thanks!

    I have the same problem discussed elsewhere in that the cursor doesn't change to a E_RESIZE_CURSOR when it's over a split panel divider. The code is in a large application too huge to post, and my attempts to simplify it have been unable to reproduce the problem. I have implemented the solution suggested in [http://forums.sun.com/thread.jspa?forumID=57&threadID=642994] but, although the mouse listener methods are indeed called, the cursor doesn't change. I have also tried calling setCursor on the parent of the JSplitPane, and on the JRootPane, but it doesn't change. In each case the mouse listener is called but the setCursor call has no effect.
    All the discussions on setCursor having no effect I've found are specific to JDialog. In my case, I have a deep window stack starting with JFrame, JRootPane, JLayeredPane, down through several JPanels, a JSplitPane, more JPanels, my JSplitPane, which contains 2 JPanels, and so on.
    What would prevent the JSplitPane divider from changing the cursor itself? Assuming it's trying, just as my explicit mouse listener is, what could be overriding, obscuring, or intercepting my cursor change?
    Any help would be most welcome
    Thanks!

  • JSplitPane divider does not change cursor in JDialog

    Hello,
    I am working with a JSplitPane added to a JDialog and when
    I try to move the divider the mouse cursor does not change
    to the resize cursor. If I add the JSplitPane to a JFrame it works
    ok. Is this a bug???
    Try the following code:
    JDialog d = new JDialog();
    d.add(new JSplitPane());
    d.setSize(640,480);
    d.setVisible(true);
    Thanks for any help!

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing
      JDialog d = new JDialog();
      public Testing()
        JSplitPane sp = new JSplitPane();
        d.add(sp);
        sp.setUI(new MyUI());
        d.setSize(640,480);
        d.setVisible(true);
      class MyUI extends javax.swing.plaf.metal.MetalSplitPaneUI
        public javax.swing.plaf.basic.BasicSplitPaneDivider createDefaultDivider()
          javax.swing.plaf.basic.BasicSplitPaneDivider divider = super.createDefaultDivider();
          divider.addMouseListener(new MouseAdapter(){
            public void mouseEntered(MouseEvent me){
              d.setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
            public void mouseExited(MouseEvent me){
              d.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
          return divider;
      public static void main(String[] args){new Testing();}
    }Message was edited by:
    Michael_Dunn
    [EDIT]
    will also need to add Cursor code for mouseDragged()

  • JSplitPane divider only goes left, but not right

    Hi, I have a application where im getting some information from a database and put it on a jtree. When I push an element in the JTree, the information comes on the right side of the JSplitPane. But I can't move it to the right side, only left. And when I choose something else further down in the hierarchy (JTree), I can drag it both left and right. So its only when I show a lot of information on the right side, when it does'nt want to resize. Any ideas anyone?

    I'd check the Dashboard & Exposé preference pane in System Preferences and see if the Desktop, All Windows or Application windows shortcuts are "Right Shift" instead of the normal F11, F9 or F10, respectively.

  • Center the JSplitPane divider inside a Jframe.

    I am trying to use the JSplitPane class. I want to set the divider in the middle of the Jframe it is in. I have size the Jframe to 500,500 and set the divider to 250. The problem is if you include the title bar of the Jframe then it looks like it is in the right spot but I don�t want to include the title bar I just want the internal part of the frame to be divided in half not the whole Jframe. Any suggestion on how to do that? Also how do you keep the divider in the center when the Jframe is resized. Thanks.

    setDividerLocation(0.5d) should do the job. if you want to set this in the constructor of your container, you should do this after everything else is done, somethinglike
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    xxx.setDividerLocation(0.5d);
    });

  • JSplitPane divider appears too large under 1.4

    I just tried my code in 1.4, and the divider of my JSplitPane starts at about 100 pixels wide. If I grab and move it, it resets to the right size. This only happens under 1.4. I've tried explicitly setting the size, but it still initially appears huge.
    Any ideas?

    Well, I've tried all your creative ideas (many thanks) - I even updated my JVM (jre 1.4b92 windows) to be sure I didn't have an old beta jvm, but nothing worked.
    However, I did find a short term hack - something that will likely bite me later. The following code is executed when a window event is triggered. Then 3 seconds later, the revalidate() is called, followed by a JFrame revalidate() and repaint(). (Sense a little frustration here?) Bottom line, I have a working hack - for now. I'll pay for my sins later....
    brian
    * @todo fix this for real - this is a hack for JDK 1.4. It is not needed in JDK 1.3
    Thread thread = new Thread(new Runnable()
    public void run()
    try
    Thread.sleep(3000);
    }catch(Exception e){}
    spPages.setDividerSize(10);
    spPages.revalidate();
    validate();
    repaint();
    System.out.println("TICKxxx");
    thread.start();

  • JSplitPane - Divider only moves to one direction.

    Hi!
    I've got a question concerning a JSplitPane I'm using in my program. I add an objecte to each of my sides. On the left I have a Canvas3d (from Java3d) and on the right a JPanel.
    Now my problem is, that the divider only moves to one direction. I've made it oneTouchExpandable and I've set the dividerLocation to 80%.
    An earlier posting says, I have to set the minimumSize of my components, but my Canvas3d (inherits from a AWT-Canvas) doesn't have the method Canvas.setMinimumSize(Dimension);
    Does anybody see a way out of this? Thanks for any help,
    joerg

    Hi Armyguy:
              To calibrated the screen. Go to all programs find this file. PC Help  &Tools click it and then click on HP Calibrations Utility click yes in next screen. You can also find it this way. In computers program search box type in HP Calibrations Utility  and run it.
            You may also have a bad malware run your Antivirus software scan as well. See if that detects and deletes any thing. If you have Microsoft Security Essential its scan. If not it is free , It detects and moves malware what antivirus do not pickup on Down Loaded from MSN.com. You also want to check your keyboard and see if some thing is pressing the keys. I know that some times if I have something laying on the keyboard it effects the mouse. You can also troubleshoot the mouse in HP Support Assistant . Open up HP Support Assistant click Troubleshoot then click around the computer Cilck on Keyboard and Mouse and other devices tab.  Both mouse and keyboard are listed.

  • JSplitPane divider drag animation

    When resizing a JSPlitPane, there is a black bar that displays on the screen in place of the divider. Is there a way to remove this black bar or change the color?

    SetContinuousLayout() along with the mouseMotionListener and a custom UI does kind of what I want, except I lose the dotted decoration and border on the divider, this is what I have so far and it works in my application, though there's probably a better class I can extend to not paint the black bar with the lastDragPosition so I don't lose the decoration.
    import java.awt.Dimension;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import javax.swing.plaf.basic.BasicSplitPaneUI;
    public class TestSplitPane {
         public TestSplitPane() {
              final JFrame frame = new JFrame();
              frame.setTitle("Test Split Pane Divider");
              JPanel topPanel = new JPanel();
              topPanel.setPreferredSize(new Dimension(400, 200));
              topPanel.setMinimumSize(new Dimension(400, 200));
              topPanel.setBorder(BorderFactory.createTitledBorder("Top Panel"));
              JPanel bottomPanel = new JPanel();
              bottomPanel.setBorder(BorderFactory.createTitledBorder("Bottom Panel"));
              final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel);
              splitPane.setUI(new MySplitPaneUI());
              splitPane.setContinuousLayout(true);
              final BasicSplitPaneUI splitPaneUI = (BasicSplitPaneUI) splitPane.getUI();
              splitPaneUI.getDivider().addMouseMotionListener(new MouseMotionListener() {
                   public void mouseMoved(MouseEvent arg0) {
                   public void mouseDragged(MouseEvent arg0) {
                        final int currentDragY = ( splitPaneUI.getDividerLocation(splitPane) + arg0.getY());
                        splitPane.setDividerLocation(currentDragY);
                        frame.invalidate();
                        frame.repaint();
              frame.add(splitPane);
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              new TestSplitPane();
         private class MySplitPaneUI extends BasicSplitPaneUI {
              public MySplitPaneUI() {
                   super();
              public int getDividerLocation(JSplitPane jc) {
                   int loc = super.getDividerLocation(jc);
                   super.setLastDragLocation(loc);
                   return loc;
    }

  • Clicking on a JSplitPane divider.

    Hi,
    This may seem like a stupid question but, how can I detect clicks on the Divider of a JSplitPane? I can make it resize programmatically, and I simply want to resize it if it's double clicked on (according to the left component's preferred size).
    Many thanks.

    I do it this way:
    // frame class fields
    protected int splitPaneDefaultDividerLocation = -1;
    protected JSplitPane splitPane;
    // inside method for initialization of frame components,
    // after splitPane is created and added to the frame content pane
        SplitPaneUI spui = splitPane.getUI();
        if (spui instanceof BasicSplitPaneUI) {
          // Setting a mouse listener directly on split pane does not work, because no events are being received.
          ((BasicSplitPaneUI) spui).getDivider().addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              if (e.getClickCount() > 1) {
                if (splitPane.getDividerLocation() != splitPaneDefaultDividerLocation) {
                  splitPane.setDividerLocation(splitPaneDefaultDividerLocation);
                } else {
                  splitPane.setDividerLocation(0);
    // splitPane.getDividerLocation() returns last value passed to splitPane.setDividerLocation()
    // so at this point it returns -1 and cannot be used
        pack(); // Layout the components.
        splitPaneDefaultDividerLocation = splitPane.getUI().getDividerLocation(splitPane);

  • JSplitPane divider too wide on first display

    I have two split panes nested into each other. For the second, inner one, I have a scrollpane with a table on the top and a scrollpane with a textpane on the bottom. When the Frame is shown for the first time, the divider for the inner splitpane is 5 times as wide as it should be.
    What makes things more complicated is that I add the Panel with the splitpane after a user event.
    Any idea,
    Joerg

    Hi,
    I ran into the same problem, and verified that calling "updateUI" on the JSplitPane does fix the problem. I do this just before I call visible on the main frame.
    Like the original poster, I also have a ScrollPane with a Jtable in one of the Split Panels. Maybe something about SplitPanes mixed with scrolly panes and/or tables causes this problem.

  • Hide Jsplitpane divider

    I have a splitpane with two panels. two panels are shown only when the user does some action. Initially, i should show only one panel. even though I have set a big value for divider, it shows up at the bottom of the panel. Can jsplitpane's divider be hidden? If yes,how?
    Thanks.

    I have a splitpane with two panels. two panels are
    shown only when the user does some action. Initially,
    i should show only one panel. even though I have set a
    big value for divider, it shows up at the bottom of
    the panel. Can jsplitpane's divider be hidden? If
    yes,how?
    Thanks.Try setBottomComponent(null);

  • JSplitPane divider issue

    When the divider of the JSplitPane is dragged, how to determine the direction of the drag. (i.e.whether is being dragged up or dragged down)

    you can use:
    BasicSplitPaneDivider divider = ((BasicSplitPaneUI)mySplitPane.getUI()).getDivider();
    BasicSplitPaneDivider extends Container so you can do everything that may be done with Container, and in your case:
    divider.addComponentListener(new ComponentAdapter(){
    public void componentMoved(ComponentEvent e){
    //chech if location is increasing or decreasing

  • 'dotted' / 'bumpy' background like JSplitPane divider

    Is there a way to get the background of a JPanel to have the nice 'dotted' (is 'bumpy' more correct ?) look of the light grey divider that Swing uses for such things as JSplitPane ?

    Too many panels you are having. Try none:
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    public class SplitExample {
         public static void main(String[] args) throws MalformedURLException {
              JLabel left = new JLabel("LEFT");
              URL url = new URL("http://weblogs.java.net/jag/bio/JagHeadshot-small.jpg");
              JLabel right = new JLabel(new ImageIcon(url));
              JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
              JFrame f = new JFrame("SplitExample");
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.getContentPane().add(sp);
              f.pack();
              f.setLocationRelativeTo(null);
              f.setVisible(true);
    }

Maybe you are looking for

  • Installed new version of iTunes and now my library is gone.

    I installed the latest version of iTunes when I got a prompt on opening iTunes. When the installation was complete, all of my music was gone. I found my library and thought I imported it to my library correctly, but every time I quit iTunes, the next

  • Can I add a document link to a Note in Mail?

    I know you can insert a URL link, but I wanted to link to a document or .pdf on my system within a Note in Mail. Thanks so much! -- Grace

  • Set parameter as empty date in OIM

    Hello I have an adapter that calls a stored procedure and need to pass null as one of the date parameters. I tried not to input anything but OIM sets the parameter value as 01/01/1970. I tried "set variable" task to set the variable as "Empty date" b

  • MIRO accounting entries

    Hi All,            i need to what are accounts those are hit when we post IR recipt in MIRO.  I got an idea GR/IR clearing accounting and vendor account should be hit. But there are so many entries when i am posting. Please provide me which transacti

  • Time machine mail

    I would like to use time machine or back up ONLY my mail.  Is that possible? Thanks.  Mike.