咨询一下,JSplitPane的分割位置怎么设定?我在程序注释了.我修改了,可是
没有变化,这是怎么回事.
package src;
import javax.swing.*;
import java.awt.*;
public class JSplitPanel extends JPanel{
public JSplitPanel(){
//设置布局管理器
setLayout(new BorderLayout());
JTree jt=new JTree();
String[] numArray={ "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten "};
JList jl=new JList(numArray);
JScrollPane left=new JScrollPane(jt);
JScrollPane right=new JScrollPane(jl);
left.setMaximumSize(new Dimension(0,0));
right.setMaximumSize(new Dimension(0,0));
//分裂Pane,水平(HORIZONTAL_SPLIT)
JSplitPane pane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,left,right);
pane.setDividerLocation(0.5);//分割位置设置???
add(pane,BorderLayout.CENTER);
}
public static void main(String[] args) {
JFrame jf=new JFrame( "JSplitPanel Example ");
jf.setSize(500,400);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jp=new JSplitPanel();
jf.getContentPane().add(jp,BorderLayout.CENTER);
jf.setVisible(true);
}
}
------解决方案--------------------
pane.setDividerLocation(0.5);//分割位置设置???
设置一个大一点的值就可以了
pane.setDividerLocation(300);//分割位置设置???
------解决方案--------------------
就是左边的 panel的宽度或者 上面panel的高度