0
我有一個問題,在構建我的shell並打開它之後,我需要在運行時將圖形元素添加到shell中 並且一旦shell打開,看不到添加的新圖形元素。 新的圖形元素出現,以防萬一我調整殼的大小。如何在ScrolledComposite中自動刷新SWT
有沒有辦法解決這個問題並自動刷新 這裏有個簡單的例子: 1-我在標籤文件夾中添加了10個A按鈕並打開了shell。 2-然後,我添加B的10個按鈕到殼體 3-我可以看到按鈕B只是如果調整殼
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TabFolder
{
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(500, 500);
shell.setLayout(new GridLayout());
final CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
folder.setSize(500, 500);
CTabItem item = new CTabItem(folder, SWT.CLOSE);
final ScrolledComposite scrollComp = new ScrolledComposite(folder, SWT.V_SCROLL | SWT.H_SCROLL);
item.setControl(scrollComp);
final Composite tab1Comp = new Composite(scrollComp, SWT.NONE);
tab1Comp.setLayout(new GridLayout(1, true));
tab1Comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
scrollComp.setContent(tab1Comp);
scrollComp.setExpandVertical(true);
scrollComp.setExpandHorizontal(true);
scrollComp.addControlListener(new ControlAdapter()
{
public void controlResized(ControlEvent e)
{
Rectangle r = scrollComp.getClientArea();
scrollComp.setMinSize(folder.computeSize(r.width, SWT.DEFAULT));
}
});
for (int x = 0; x < 10; x++)
{
Button text = new Button(tab1Comp, SWT.NONE);
text.setText("A");
}
shell.open();
for (int x = 10; x < 20; x++)
{
Button text = new Button(tab1Comp, SWT.NONE);
text.setText("B");
}
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
感謝。
非常感謝您的回答 感謝您的幫助 – user1205079 2012-02-14 16:28:41