谁你能告诉我原因吗?

simon1006 2007-03-06 04:02:24
//
首先,在JFrame 显示出来的时候,为什么bottom.setDividerLocation(0.5);
显示不出来正确的位置,当点击按钮
JButton b=new JButton("real divider");
就能正确显示分割线的位置
代码如下:
//
package swingTest;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class ScrollPaneTest {
public static void main(String[] arg){
JFrame f=new JFrame();
f.setSize(600,500);
f.setLocation(250,250);
Container c= f.getContentPane();
c.setLayout(new BorderLayout());


final JSplitPane left=new JSplitPane(JSplitPane.VERTICAL_SPLIT,new JPanel(),new JPanel());

JPanel p1=new JPanel();
JButton b=new JButton("real divider");
p1.add(b);

JPanel p2=new JPanel();
JPanel p3=new JPanel();
final JSplitPane bottom=new JSplitPane(JSplitPane.VERTICAL_SPLIT,p2,p3);
final JSplitPane right=new JSplitPane(JSplitPane.VERTICAL_SPLIT,p1,bottom);
JPanel leftPanel=new JPanel(new BorderLayout());
// leftPanel.add(left,BorderLayout.CENTER);
final JSplitPane top=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,left,right);
c.add(top,BorderLayout.CENTER);

f.setVisible(true);

top.setDividerLocation(0.7);
right.setDividerLocation(0.3);
bottom.setDividerLocation(0.5);
left.setDividerLocation(0.8);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
top.setDividerLocation(0.7);
right.setDividerLocation(0.3);
bottom.setDividerLocation(0.5);
left.setDividerLocation(0.8);
}
});


}
}
...全文
216 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
simon1006 2007-03-06
  • 打赏
  • 举报
回复
发错地方了,呵呵 转到GUI
dashi 2007-03-06
  • 打赏
  • 举报
回复

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧