1
現在、テーブルヘッダーの高さを設定する際に問題があります。ここに私のコードです:SWTテーブルのヘッダの高さを設定する方法は?
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
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 = { "titleioioio", "C", "!", "Description", "Resource", "In Folder", "Location" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText(titles[i]);
}
int count = 10;
for (int i = 0; i < count; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(0, "x");
item.setText(1, "y");
item.setText(2, "!");
item.setText(3, "this stuff behaves the way I expect");
item.setText(4, "almost everywhere");
item.setText(5, "some.folder");
item.setText(6, "line " + i + " in nowhere");
}
table.pack();
for (int i = 0; i < titles.length; i++) {
table.getColumn(i).pack();
}
Button button = new Button(shell, SWT.PUSH);
button.setText("change font");
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) {
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
このテーブルヘッダーの高さを設定する方法はありますか?私はとTableColumn
にsetSize()
メソッドを見つけようとしましたが、存在しません。
「テーブルヘッダーの高さを設定する際に問題があります」 - 何が問題なのですか?そして、なぜ高さを手動で設定する必要がありますか?あなたの例を使ってフォントサイズを変更すると、すべての行とヘッダーが予想どおりに更新されました。 – avojak
問題は「テキストのサイズを変更せずにヘッダーの高さを変更したい」という問題です。 :D –