0
A
回答
4
Table
談到在SWT
和其他TableViewer
談到在JFace
。所以目前尚不清楚您是否需要TableViewer
或Table
的解決方案。同樣在沒有任何代碼片段的情況下,我選擇演示JFace
和TableViewer
,但該概念對於Table
和SWT
將保持不變。
>>設置字體
>>設置字體
你可以看到頭部高度差之後之前。
>>代碼
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class TVHeaderTest
{
private class MyContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
return (MyModel[])inputElement;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
public class MyModel {
public int counter;
public MyModel(int counter) {
this.counter = counter;
}
public String toString() {
return "Item " + this.counter;
}
}
private static Display display;
public TVHeaderTest(final Shell shell)
{
final Table table = new Table (shell, SWT.H_SCROLL|SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION|SWT.CHECK);
table.setLinesVisible (true);
table.setHeaderVisible (true);
final String[] titles = {"!", "Description", "Resource", "In Folder", "Location"};
for (int i=0; i<titles.length; i++) {
TableColumn column = new TableColumn (table, SWT.NONE);
column.setText (titles [i]);
column.setWidth(100);
}
final TableViewer v = new TableViewer(table);
v.setLabelProvider(new LabelProvider());
v.setContentProvider(new MyContentProvider());
MyModel[] model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
Button button = new Button(shell, SWT.PUSH);
button.setText("Set Font");
// FOCUS ON THIS PART - START
button.addSelectionListener(new SelectionListener()
{
public void widgetSelected(SelectionEvent e)
{
FontDialog d = new FontDialog(shell);
FontData data = d.open();
table.setFont(new Font(display, data));
for (int i = 0; i < titles.length; i++) {
table.getColumn(i).pack();
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
// FOCUS ON THIS PART - END
shell.pack();
}
private MyModel[] createModel() {
MyModel[] elements = new MyModel[10];
for(int i = 0; i < 10; i++) {
elements[i] = new MyModel(i);
}
return elements;
}
public static void main(String[] args)
{
display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
new TVHeaderTest(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
結帳// FOCUS ON THIS PART - START
和// FOCUS ON THIS PART - END
意見之間的代碼。
此外,你不能這樣做設置標題圖像。查看Table Header Image Bug
相關問題
- 1. SWT TableViewer彙總行
- 2. SWT - TableViewer - 刷新選擇
- 3. JFace/SWT多行TableViewer行
- 4. 在SWT中拖放tableviewer
- 5. SWT通過TAB移動TableViewer
- 6. SWT樹項目高度
- 7. WP7標題高度
- 8. SWT TableViewer無選擇的多重選擇
- 9. 如何在TabFolder中嵌入SWT TableViewer?
- 10. 添加的JFace的TableViewer到SWT表
- 11. 如何使TableViewer在SWT中可擴展?
- 12. swt jface tableviewer按數據獲取行
- 13. SWT - 在我的TableViewer中使用EditingSupport
- 14. JFace SWT TableViewer中的圖像和文本
- 15. CSS 100%高度+標題靜態高度;
- 16. SWT:從標籤標題中刪除高亮
- 17. 標題邊緣的高度
- 18. UINavigationBar navigationItem標題高度
- 19. TabControl標題的高度
- 20. 問題有標籤高度
- 21. css圖標高度問題
- 22. 降低標題的高度
- 23. QDockWidget標題欄高度
- 24. <rich:dataTable>標題高度
- 25. 尊重標題高度
- 26. SmartGwt窗口標題高度
- 27. 無標題線高度的Html錨高度問題
- 28. 如何設置SWT ToolItem的高度?
- 29. SWT:使用MouseListener調整表格(高度)
- 30. WPF行標題寬度和列標題高度調整大小
感謝您的回覆!是的,我的意思是JFace中的TableViewer(我不知道JFace和SWT有什麼區別)。從我可以看到你的代碼和我一樣,使用.setFont()。但是在我的機器上(Windows XP),標題的高度保持不變。當我運行你的代碼時也會發生這種情況:http://www.abload.de/image.php?img=swttableviewerfzk5.png - 似乎是一個Windows問題。任何想法如何解決或解決這個問題? – Dexter 2011-04-27 23:28:39
@Dexter:是的,它似乎是一個操作系統相關的問題。根據我發佈的** Bug **鏈接:'這是一個平臺限制。 Windows不會增長標題的高度。已知SWT可直接訪問操作系統小部件。所以窗口限制擴展到SWT。雖然,評論發佈於2006年,但我最好的猜測是它是用於XP的。作爲一個工作,請看http://sourceforge.net/projects/ktable/和http://www.eclipse.org/nebula/widgets/grid/grid.php。 – Favonius 2011-04-28 05:30:12