How do I remove Swing JSplitPane intermediate styles?

79 views Asked by At

How do I remove Swing JSplitPane intermediate styles?

BasicSplitPaneDivider

https://i.stack.imgur.com/97rrg.png

1

There are 1 answers

0
camickr On

As mentioned in the comment the proper solution is to create a custom BasicSplitPaneDivider.

As a hack you can access the divider and add your own button to it:

    BasicSplitPaneUI ui = (BasicSplitPaneUI)splitPane.getUI();
    BasicSplitPaneDivider divider = ui.getDivider();

    divider.setDividerSize(25);
    JButton up = (JButton)divider.getComponent(0);
    up.setPreferredSize( up.getSize() );
    up.setMaximumSize(up.getPreferredSize());
    up.setAlignmentY(0.5f);

    JButton down = (JButton)divider.getComponent(1);
    down.setPreferredSize( down.getSize() );
    down.setMaximumSize(down.getPreferredSize());
    down.setAlignmentY(0.5f);

    divider.setLayout( new BoxLayout(divider, BoxLayout.X_AXIS));
    divider.add(up);
    divider.add(down);
    divider.add(Box.createHorizontalGlue());
    System.out.println(divider.getLayout());
    JButton button = new JButton("Click Me");
    button.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    divider.add(button);
    divider.revalidate();
    divider.repaint();

The above code would need to be executed AFTER the frame has been realized.

In any case the above will demonstrate the type of changes that need to be made to the BasicSplitPaneDivider class.