所以,我的问题归结为这...默认的分隔线是一种丑陋的,再加上我想添加一个标签(在我想要的文本在它的意义上,而不是在“添加一个JLabel到它的布局“感觉)。我看到你可以改变分割窗格分隔线上的边框,但是当我这样做时,它将删除我想要保留的单触箭头。如何定制JSplitPane分隔线并保持一键式箭头功能?
任何想法,我怎么能有两个?
以下是一个演示这两个默认行为和SSCCE什么,当我改变分隔边境发生的情况:
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);
}
}
+ 1代表[sscce](http://sscce.org/)。 – trashgod
您可以将标题边框放在分割窗格的内容中吗? – trashgod
是的,关于标签,我可以。我仍然想要一种方式来改变分隔线的外观,而不是摆脱一触式箭头。 –