6

だから、私の問題はこれに要約されます...デフォルトの仕切りはちょっと醜いので、それにラベルを追加したいと思います(「JLabelを追加する」ではなく、テキストをオンにしたいという意味で)そのレイアウト」の意味に)。分割ペイン ディバイダーの境界線を変更できるようですが、変更するとワンタッチ矢印が削除されてしまいます。

どうすれば両方を持つことができるかについて何か考えはありますか?

これは、デフォルトの動作と、分割線を変更したときに何が起こるかを示す 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);
}
}
4

1 に答える 1

3

分割ペインの仕切りの境界線を変更できるようですが、変更すると、残しておきたいワンタッチ矢印が削除されます。

于 2012-06-15T19:59:59.133 に答える