我有一个JSplitPane,当显示时,应分割窗格的50%。
现在给setDividerLocation一个0.5的参数(建议),Java似乎把它当作一个正常的数字,而不是百分比。如在中所示,分隔线不是位于窗格的中间,而是几乎位于左侧窗格的开头(窗格是垂直拆分的)。有什么解决办法吗?
发布于 2011-08-15 03:34:03
我是不是遗漏了什么?这个问题似乎有很多令人费解的答案……但我认为一个简单的setResizeWeight(0.5)就可以解决这个问题……SplitPane Tutorial中对此进行了描述
发布于 2009-12-10 15:08:11
setDividerLocation( double )方法只适用于“已实现”的框架,这意味着在打包或使框架可见之后。
可以在任何时候使用setDividerLocation( int )方法。
发布于 2012-12-29 03:51:28
仅当拆分窗格可见时,才能将拆分窗格分隔线的位置设置为百分比。您可以点击拆分窗格所有者的事件来确定何时可以设置分隔线的位置。例如:
public class MyFrame extends JFrame {
public MyFrame() {
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
// ... set up the split pane, and add to the frame ...
// Listen for the frame's "shown" event.
addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent componentEvent) {
// Set the divider location to 20%.
// This works because we know the pane is visible.
splitPane.setDividerLocation(.2);
// Stop listening for "shown" events.
removeComponentListener(this);
}
});
pack();
}
}https://stackoverflow.com/questions/1879091
复制相似问题