[英]Setting swt table column foreground color
有什么方法可以設置SWT表列的前景色和/或背景色?還是SWT表頭的前景色和背景色? setForeground / setBackground方法在org.eclipse.swt.widgets.TableColumn上不可用
不能。無法在TableColumn上設置背景/前景(取決於本機支持)。 您可能需要自定義繪制標題。 使默認標題不可見,並在單獨的畫布中繪制您自己的標題,您需要使其與TableColumn
和Table
滾動保持同步。
org.eclipse.swt.widgets.Table.setHeaderVisible(boolean)
TableItem
有setBackground()
和setForeground()
方法。
如果您希望能夠更有效地自定義項目,則建議改用TableViewer
。
這是帶有樣式示例的出色教程。
這是帶有彩色列的簡單Table
一些示例代碼:
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new FillLayout());
Table table = new Table(shell, SWT.NONE);
table.setHeaderVisible(true);
for(int col = 0; col < 3; col++)
{
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText("Column " + col);
}
Color color = display.getSystemColor(SWT.COLOR_YELLOW);
for(int row = 0; row < 10; row++)
{
TableItem item = new TableItem(table, SWT.NONE);
for(int col = 0; col < 3; col++)
{
item.setText(col, "Item " + row + " Column " + col);
if(col == 1)
{
item.setBackground(col, color);
}
}
}
for(int col = 0; col < 3; col++)
{
table.getColumn(col).pack();
}
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.