java JSplitPane 设置可调整大小的 false
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7065309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSplitPane set resizable false
提问by Tapas Bose
How to make JSplitPane
to resizable false
? I didn't want to resize the JSplitPane
, I used it for the border of this pane. Is there any other way to create same border structure to split a panel vertically into two parts.
如何JSplitPane
调整大小false
?我不想调整 的大小JSplitPane
,我将它用于此窗格的边框。有没有其他方法可以创建相同的边框结构以将面板垂直分成两部分。
采纳答案by oliholz
You can override the JSplitPane methodes getDividerLocation()
and getLastDividerLocation
and return a constant value.
您可以覆盖调整JSplitPane methodesgetDividerLocation()
和getLastDividerLocation
并返回一个恒定值。
JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT){
private final int location = 100;
{
setDividerLocation( location );
}
@Override
public int getDividerLocation() {
return location ;
}
@Override
public int getLastDividerLocation() {
return location ;
}
};
回答by camickr
splitPane.setEnabled( false );
回答by sers
For preventing users to resize the panes you can also set the divider size to zero.
为了防止用户调整窗格大小,您还可以将分隔符大小设置为零。
splitPane.setDividerSize(0);
回答by mKorbel
Consider for using Compound Borderswith EtchedBorder
请考虑使用复合边框与EtchedBorder
回答by david
final double pos = split.getDividers().get(0).getPosition();
split.getDividers().get(0).positionProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> arg0,
Number arg1, Number arg2) {
split.getDividers().get(0).setPosition(pos);
}
});
回答by TrogloGeek
As stated un @camickr answer comments, disabling the whole split pane can disable contained components interactive behavior (for example, they won't show their interactive cursors on hover)
正如@camickr 回答评论所述,禁用整个拆分窗格可以禁用包含的组件交互行为(例如,它们不会在悬停时显示其交互式光标)
instead, if using BasicSplitPaneUI, you can disable the divider from the UI
相反,如果使用 BasicSplitPaneUI,您可以从 UI 中禁用分隔线
public class MySplitPane extends JSplitPane {
public void setResizable(boolean resizable) {
BasicSplitPaneUIui = (BasicSplitPaneUI) this.getUI();
ui.getDivider().setEnabled(resizable);
}
}