这是我的示例代码,我在我的类中有一个名为CommentPage的部分,扩展为FormPage,我在本节中使用了scrolledComposite来显示一些内容,但它确实有效,Dose任何人都知道为什么?
"test1test2test3"
我的问题:
为什么方法scrolledContainer
中commentArea
中的标签文字{{1}}没有显示?
答案 0 :(得分:1)
使用ScrolledComposite
上的setExpandHorizontal
方法:
ScrolledComposite scrollContainer = new ScrolledComposite(container, SWT.V_SCROLL|SWT.BORDER);
scrollContainer.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false));
scrollContainer.setExpandVertical(true);
scrollContainer.setExpandHorizontal(true); // Add this line
将代码中的ScrolledComposite
段提取为易于测试的内容:
public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
// Your code below
final ScrolledComposite scrollContainer = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.BORDER);
scrollContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
scrollContainer.setExpandVertical(true);
scrollContainer.setExpandHorizontal(true); // Added
scrollContainer.setAlwaysShowScrollBars(true);
final Color white = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
scrollContainer.setBackground(white);
final Composite scrollInner = new Composite(scrollContainer, SWT.NONE);
scrollInner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
scrollInner.setBackground(white);
scrollInner.setLayout(new GridLayout(1, false));
final Label text = new Label(scrollInner, SWT.NONE);
text.setText("test1test2test3");
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
scrollContainer.setContent(scrollInner);
// End your code
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}