Java SWT设置ScrolledComposite内部组件的最大高度
我不知道如何正确设置行组合的高度。我希望下面的代码片段只显示一行数据。使用滚动条可以看到任何其他行。我尝试过使用rowContainer.setSize(),但没有效果。任何帮助都将不胜感激 请注意,滚动的组合不是直接链接到rowContainer组合,而是包含其他组合Java SWT设置ScrolledComposite内部组件的最大高度,java,swt,Java,Swt,我不知道如何正确设置行组合的高度。我希望下面的代码片段只显示一行数据。使用滚动条可以看到任何其他行。我尝试过使用rowContainer.setSize(),但没有效果。任何帮助都将不胜感激 请注意,滚动的组合不是直接链接到rowContainer组合,而是包含其他组合 private void doStuff(final Composite parentContainer) { final ScrolledComposite scrolledComposite = new Scroll
private void doStuff(final Composite parentContainer) {
final ScrolledComposite scrolledComposite = new ScrolledComposite(
parentContainer, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
final Composite borderComposite = new Composite(scrolledComposite,
SWT.BORDER);
borderComposite.setLayout(new GridLayout(1, false));
borderComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
scrolledComposite.setContent(borderComposite);
scrolledComposite.setSize(borderComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT));
// Create a container for a label and button
final Composite labelAndAddButtonContainer = new Composite(
borderComposite, SWT.NONE);
labelAndAddButtonContainer.setLayout(new GridLayout(2, false));
labelAndAddButtonContainer.setLayoutData(new GridData(SWT.LEFT,
SWT.TOP, false, false));
// Create a container to hold all dynamic rows
final Composite rowContainer = new Composite(borderComposite, SWT.NONE);
rowContainer.setLayout(new GridLayout(1, false));
rowContainer.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
// Create at least one row.
final Collection<String> rowData = getRowData();
if (rowData.isEmpty()) {
createRow(scrolledComposite, rowContainer, "");
} else {
for (final String text : rowData) {
createRow(scrolledComposite, rowContainer, text);
}
// How do I adjust for the height so that only 1 row shows,
// and scrollbars appear if there is more than one row?
}
// Create a button
final Button addButton = new Button(labelAndAddButtonContainer,
SWT.PUSH);
addButton.setImage(someImage);
final Label label = new Label(labelAndAddButtonContainer, SWT.NONE);
label.setText("SOME_LABEL");
}
private void doStuff(最终复合父容器){
最终ScrolledComposite ScrolledComposite=新ScrolledComposite(
父容器,SWT.BORDER | SWT.H|u卷轴| SWT.V|u卷轴);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setLayoutData(新的GridData(SWT.FILL、SWT.FILL、,
对,对),;
最终复合边界复合=新复合(滚动复合,
边界);
setLayout(新的GridLayout(1,false));
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,
是的);
scrolledComposite.setContent(borderComposite);
scrolledComposite.setSize(borderComposite.computeSize(SWT.DEFAULT,
主权债务违约),;
//为标签和按钮创建容器
最终复合材料LabelAndButtonContainer=新复合材料(
复合材料,SWT,无);
setLayout(新的GridLayout(2,false));
LabelAndButtonContainer.setLayoutData(新网格数据(SWT.LEFT,
SWT.TOP,false,false);
//创建一个容器以容纳所有动态行
最终组合行容器=新组合(borderComposite,SWT.NONE);
setLayout(新的GridLayout(1,false));
setLayoutData(新的GridData(SWT.FILL,SWT.NONE,true,false));
//至少创建一行。
最终集合rowData=getRowData();
if(rowData.isEmpty()){
createRow(scrolledComposite,rowContainer,“”);
}否则{
for(最终字符串文本:rowData){
createRow(scrolledComposite、rowContainer、text);
}
//如何调整高度,以便仅显示一行,
//如果有多行,会出现滚动条吗?
}
//创建一个按钮
最终按钮添加按钮=新按钮(LabelAndButtonContainer,
推);
addButton.setImage(someImage);
最终标签=新标签(LabelAndButtonContainer,SWT.NONE);
label.setText(“一些标签”);
}