1
A
回答
3
因爲你沒有說過你在何時,在哪裏以及如何設置複合尺寸,所以我假設你正在設置一個事件的大小,以及setSize
適合我。
我在Win7,eclipse 4.2和JDK 1.6_b30上。參見示例代碼:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
public class Test
{
public static void main(String[] args) throws Exception
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
TabFolder folder = new TabFolder(shell, SWT.TOP);
folder.setLayout(new GridLayout());
folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TabItem item = new TabItem(folder, SWT.NONE);
item.setText("Tab 1");
final Composite composite = new Composite(folder, SWT.BORDER);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Text text = new Text(composite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
text.setText("Tab 1");
Button b = new Button(composite, SWT.PUSH);
b.setText("Press");
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
composite.setSize(23, 43);
}
});
item.setControl(composite);
shell.setSize(300, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Before Pressing the Button
After Pressing the Button
雖然有趕上!只要您調整應用程序的大小,複合材料就會回到的原始尺寸!
也有 可能是一個問題,如果你不使用設置大小的任何事件(可能在SWT標籤文件夾了一些bug或功能)。非侵入性的
hack
(不需要任何用戶交互)是使用
PaintListener
。請參見下面的代碼:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
public class Test
{
public static void main(String[] args) throws Exception
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
final TabFolder folder = new TabFolder(shell, SWT.TOP);
folder.setLayout(new GridLayout());
folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TabItem item = new TabItem(folder, SWT.NONE);
item.setText("Tab 1");
final Composite composite = new Composite(folder, SWT.BORDER);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Text text = new Text(composite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
text.setText("Tab 1");
folder.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
composite.setSize(23, 43);
}
});
item.setControl(composite);
shell.setSize(300, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
的PaintListener
解決方案是不是一個非常優雅的解決方案,但它適合我的發展環境。
相關問題
- 1. SWT的JFace:SelectionProvider在TabFolder中
- 2. SWT TabFolder懶加載
- 3. SWT TabFolder中:古怪的繪圖行爲
- 4. SWT Composite Transform
- 5. 在SWT中獲取活動標籤TabFolder
- 6. 如何在TabFolder中嵌入SWT TableViewer?
- 7. 將TabFolder大小內容的ScrolledCompsite設置爲零
- 8. SWT TabFolder垂直方向
- 9. SWT Composite出現在右邊
- 10. 如何在SWT中設置MenuItem的字體大小?
- 11. SWT - 你如何重新設置一個位於另一個複合材料內的Composite的大小/設置大小?
- 12. Java SWT Composite 1 px padding
- 13. SWT Composite需要3.6.1中的包()
- 14. SWT TabFolder有什麼替代方案?
- 15. 試圖在SWT的選項卡中設置按鈕的大小/位置
- 16. 在SWT中設置顏色
- 17. 設置Java SWT shell窗口內部區域的大小
- 18. 避免在SWT中的窗口構件中設置父窗口?
- 19. Java SWT與線程「主」java.lang.NoClassDefFoundError:org/eclipse/swt/widgets/Composite的maven異常
- 20. SWT - 如何更改TabFolder中現有TabItem的順序
- 21. 如何設置SWT ToolItem的高度?
- 22. 將固定大小設置爲SWT標籤
- 23. SWT設置外殼大小以跨越多個顯示器
- 24. 在swt中調整大小問題
- 25. 設置大小
- 26. 如何在樹中設置treeItems的最大級別(SWT)?
- 27. 在配置中設置批量大小
- 28. SWT中不同大小的視圖
- 29. 更改SWT中的字體大小
- 30. 在JScrollPane和JPanel中設置JTable的大小和JFrame的大小