import java.awt.*; import javax.swing.*;public class Test extends JFrame {
public Test() { JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(new JButton("One")), new JScrollPane(new JButton("Two"))); //splitter.setDividerLocation(0.66); // Don't work.
this.getContentPane().add(splitter); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(400, 400); this.setVisible(true); splitter.setDividerLocation(0.66); // OK }
public static void main(String[] args) { new Test(); } }
JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent)
创建一个具有指定方向和不连续重绘的指定组件的新 JSplitPane。setDividerLocation(double proportionalLocation)
设置分隔条的位置为 JSplitPane 大小的一个百分比。
import javax.swing.*;public class Test extends JFrame {
public Test() {
JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(new JButton("One")), new JScrollPane(new JButton("Two")));
//splitter.setDividerLocation(0.66); // Don't work.
this.getContentPane().add(splitter);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 400);
this.setVisible(true);
splitter.setDividerLocation(0.66); // OK
}
public static void main(String[] args) {
new Test();
}
}