SplitPane设置左右大小问题 有个setdividerlacation()方法,setdividerlacation(0.1)怎么和setdividerlacation(0.5)一样啊,运行后没任何变化,为什么?怎么才能设置成我想要的比例. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 因为你在组件显示之前就设了位置,那样是不行的,你得在整个界面显示出来,再设定setdividerlacation(0.5),(应该在你把FRAME设为VISLBLE(TRUE)之后设定)就起作用了,你试一试 import java.awt.BorderLayout;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import javax.swing.JFrame;import javax.swing.JSplitPane;public class T { public static void main(String[] args) { final JSplitPane splitPane = new JSplitPane(); splitPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { splitPane.setDividerLocation(0.7); } }); JFrame f = new JFrame(); f.getContentPane().add(splitPane, BorderLayout.CENTER); f.setSize(300, 300); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); splitPane.setDividerLocation(0.7); }} 如果你多大都是0.7, 为什么要用SplitPane? 那当最大时 splitPane.setDividerLocation(0.7)再设置一下,可能还要用到UPDATEUI(); 关于JTable中单元格的修改 java 去掉字符串中的字符 sha加密后,为什么每个字节都要和0xff 与一下? File如何返回获取的文件名子! 菜鸟求助日历输出问题 菜鸟提问,流水号! 1。基本数据类型和引用数据类型的区别? 监测程序或系统运行时间的方法,有吗? 请教有没有考虑编程性能的资料,紧急 请教浏览器的问题 为什么Random这么慢? 在JTable中实现数据库增删查改
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;import javax.swing.JFrame;
import javax.swing.JSplitPane;public class T {
public static void main(String[] args) {
final JSplitPane splitPane = new JSplitPane();
splitPane.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e)
{
splitPane.setDividerLocation(0.7);
}
});
JFrame f = new JFrame();
f.getContentPane().add(splitPane, BorderLayout.CENTER);
f.setSize(300, 300);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
splitPane.setDividerLocation(0.7);
}
}