How to configure the JSplitPane separator and maintain the functionality of one-touch arrows?

So my problem boils down to this ... By default, delimiters look ugly, plus I would like to add a shortcut to it (in the sense of I-want-text-on-it, and not in "adding JLabel to my layout" makes sense ") I see that you can change the border on the separator of the shared panels, but when I do this, it removes the one-touch arrows that I want to keep.

Any thoughts on how I can have both?

Here is SSCCE, which demonstrates the default behavior and what happens when I change the delimiter 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 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); } } 
+6
source share
1 answer

I see that you can change the border on the separator of the shared panels, but when I do this, it removes the one-touch arrows that I want to keep.

+3
source

Source: https://habr.com/ru/post/918215/


All Articles