6

So, my problem boils down to this... The default dividers are kind of ugly, plus I would like to add a label to it (in the I-want-text-on-it sense, not in the "adding a JLabel to its layout" sense). I see that you can change the border on the split pane divider, but when I do that, it removes the one-touch arrows, which I want to keep around.

Any thoughts on how I can have both?

Here's a SSCCE that demonstrates both the default behavior and what happens when I change the divider border:

import javax.swing.*;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SplitPaneFun {
public static void main(String[] args) {

        //Here I'm messing around with the divider look. This seems to remove the one-touch arrows.  These blocked-out lines illustrate
        // what I'm doing to modify the divider's border.  Does this look right?:
    //------------------------------------------------------------------------------------------------
    JSplitPane withCustomDivider = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JPanel(), new JPanel());
    BasicSplitPaneDivider divider = ( (BasicSplitPaneUI) withCustomDivider.getUI()).getDivider();
    withCustomDivider.setOneTouchExpandable(true);
    divider.setDividerSize(15);
    divider.setBorder(BorderFactory.createTitledBorder(divider.getBorder(), "Custom border title -- gets rid of the one-touch arrows!"));
    //------------------------------------------------------------------------------------------------

        //build a different splitpane with the default look and behavior just for comparison
    JSplitPane withDefaultDivider = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JPanel(), new JPanel());
    withDefaultDivider.setOneTouchExpandable(true);

        //slap it all together and show it...
    CardLayout splitsLayout = new CardLayout();
    final JPanel splits = new JPanel(splitsLayout);
    splits.add(withCustomDivider, "custom");
    splits.add(withDefaultDivider,"default");

    JButton toggle = new JButton( "click to see the other split pane");
    toggle.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            ((CardLayout)splits.getLayout()).next(splits);
        }
    });

    JFrame frame = new JFrame("Split Pane Divider Comparison");
     frame.setLayout(new BorderLayout());
    frame.add(splits, BorderLayout.CENTER);
    frame.add(toggle, BorderLayout.PAGE_END);
    frame.setSize(600,500);
    frame.setVisible(true);
}
}
Cary Young
  • 85
  • 1
  • 6
  • 3
    +1 for [sscce](http://sscce.org/). – trashgod Jun 15 '12 at 19:46
  • Can you put the titled border in the split pane's content? – trashgod Jun 15 '12 at 20:08
  • Yeah, in regards to the label, I could. I'd still like a way to change the way the divider looks without getting rid of the one-touch arrows though. – Cary Young Jun 15 '12 at 20:49
  • 1
    Ah, you want the label to be visible when either pane is one-touch closed. As @mKorbel notes, that will require a new `BasicSplitPaneDivider`. It's not a solution, but `setDividerSize(50)` lets the one-touch controls show. You can `add(new Label(...))`, too. – trashgod Jun 15 '12 at 20:56
  • 1
    aaach if you want to Big Fun then you can to use [SwingUtils by Darryl Burke](http://tips4java.wordpress.com/2008/11/13/swing-utils/), all visible elements could be accessible, but again you have to know from which (J)Components are built concrete visual element – mKorbel Jun 15 '12 at 21:22

1 Answers1

3

I see that you can change the border on the split pane divider, but when I do that, it removes the one-touch arrows, which I want to keep around.

  • all these methods is possible to override the events from Mouse(Xxx)Listener, PropertyChangeListener and ButtonModel, nothing better around as Substance SubstanceSplitPaneDivider

  • part of Custom Look and Feels override these methods too

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • +1 for considering the UI delegate; nothing easier comes to mind. – trashgod Jun 15 '12 at 20:57
  • @trashgod thanks Fridays_Flame_War why bothering with Custom L&F, for example (crazy) Nimbus very well to override output to the screen from big three dinosauruses JTabbedPane, JSlider and JSplitPane :-) – mKorbel Jun 15 '12 at 21:05
  • 1
    I've seen some user resistance to forcing a particular L&F, but Nimbus is generally well accepted. – trashgod Jun 15 '12 at 21:12