Eclipse RCP 应用程序中的 NatTable 单元格不会出现边框
Borders dont appear to NatTable Cells in Eclipse RCP application
我都尝试过:设置主题配置和在配置注册表中注册带有边框样式的样式。但我没有看到边界。还有什么我想念的吗?
在我的 postConstruct 方法中,我按如下方式初始化 NatTable:
final ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration(imageRightUp, imageTreeRightDown);
TextPainter textPainter = new TextPainter(true, false);
ImagePainter imagePainter = new ImagePainter(threeDots);
CellPainterDecorator cellPainterDecorator = new CellPainterDecorator(textPainter, CellEdgeEnum.RIGHT, imagePainter);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
cellPainterDecorator,
DisplayMode.NORMAL,
LABEL_1);
Style style = new Style();
style.setAttributeValue(
CellStyleAttributes.BACKGROUND_COLOR,
GUIHelper.getColor(44, 104, 125));
style.setAttributeValue(
CellStyleAttributes.FOREGROUND_COLOR,
GUIHelper.COLOR_WHITE);
style.setAttributeValue(
CellStyleAttributes.BORDER_STYLE,
new BorderStyle(5, GUIHelper.COLOR_BLACK, LineStyleEnum.SOLID));
configRegistry.registerConfigAttribute(
// attribute to apply
CellConfigAttributes.CELL_STYLE,
// value of the attribute
style,
// apply during normal rendering i.e not
// during selection or edit
DisplayMode.NORMAL,
// apply the above for all cells with this label
LABEL_1);
configRegistry.registerConfigAttribute(
// attribute to apply
CellConfigAttributes.CELL_STYLE,
// value of the attribute
style,
// apply during normal rendering i.e not
// during selection or edit
DisplayMode.NORMAL,
// apply the above for all cells with this label
LABEL_2);
NatTable natTable = new NatTable(parent, viewportLayer, false);
GridData d = new GridData(SWT.FILL, SWT.FILL, true, true, 1,1);
natTable.setLayoutData(d);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultTreeLayerConfiguration(treeLayer));
natTable.setTheme(modernTheme);
natTable.configure();
这也是主题配置:
public class ModernNatTableThemeConfiguration extends DefaultNatTableThemeConfiguration {
public ModernNatTableThemeConfiguration( Image imageRightUp, Image imageTreeRightDown ){
TreeImagePainter treeImagePainter = new TreeImagePainter(
false,
imageRightUp, imageTreeRightDown, null); //$NON-NLS-1$//$NON-NLS-2$
this.treeStructurePainter = new BackgroundPainter(new PaddingDecorator(
new IndentedTreeImagePainter(10, null, CellEdgeEnum.LEFT,
treeImagePainter, false, 2, true), 0, 5, 0, 5, false));
TreeImagePainter treeSelectionImagePainter = new TreeImagePainter(
false,
imageRightUp, imageTreeRightDown, null); //$NON-NLS-1$//$NON-NLS-2$
this.treeStructureSelectionPainter = new BackgroundPainter(
new PaddingDecorator(new IndentedTreeImagePainter(10, null,
CellEdgeEnum.LEFT, treeSelectionImagePainter, false, 2,
true), 0, 5, 0, 5, false));
this.treeBgColor = GUIHelper.getColor(44, 104, 125);
this.treeFgColor = GUIHelper.getColor(44, 104, 125);
}
}
我想我们需要弄清楚这些条款。你想删除边框或网格线吗?因为你在样式配置中指定了边框,所以边框应该在那里。
如果你想摆脱网格线,你需要配置CellLayerPainter
。
可以这样做,例如:
configRegistry.registerConfigAttribute(
CellConfigAttributes.RENDER_GRID_LINES,
Boolean.FALSE);
顺便说一句,像您在代码中所做的那样直接修改 ConfigRegistry
不是一个好习惯。您应该创建一个 IConfiguration
(例如 AbstractRegistryConfiguration
)并将 IConfiguration
注册到您的 NatTable 实例。否则 NatTable#configure()
可能会在配置时覆盖您的更改。
此处解释如下:http://www.vogella.com/tutorials/NatTable/article.html#architecture_configuration
我都尝试过:设置主题配置和在配置注册表中注册带有边框样式的样式。但我没有看到边界。还有什么我想念的吗?
在我的 postConstruct 方法中,我按如下方式初始化 NatTable:
final ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration(imageRightUp, imageTreeRightDown);
TextPainter textPainter = new TextPainter(true, false);
ImagePainter imagePainter = new ImagePainter(threeDots);
CellPainterDecorator cellPainterDecorator = new CellPainterDecorator(textPainter, CellEdgeEnum.RIGHT, imagePainter);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
cellPainterDecorator,
DisplayMode.NORMAL,
LABEL_1);
Style style = new Style();
style.setAttributeValue(
CellStyleAttributes.BACKGROUND_COLOR,
GUIHelper.getColor(44, 104, 125));
style.setAttributeValue(
CellStyleAttributes.FOREGROUND_COLOR,
GUIHelper.COLOR_WHITE);
style.setAttributeValue(
CellStyleAttributes.BORDER_STYLE,
new BorderStyle(5, GUIHelper.COLOR_BLACK, LineStyleEnum.SOLID));
configRegistry.registerConfigAttribute(
// attribute to apply
CellConfigAttributes.CELL_STYLE,
// value of the attribute
style,
// apply during normal rendering i.e not
// during selection or edit
DisplayMode.NORMAL,
// apply the above for all cells with this label
LABEL_1);
configRegistry.registerConfigAttribute(
// attribute to apply
CellConfigAttributes.CELL_STYLE,
// value of the attribute
style,
// apply during normal rendering i.e not
// during selection or edit
DisplayMode.NORMAL,
// apply the above for all cells with this label
LABEL_2);
NatTable natTable = new NatTable(parent, viewportLayer, false);
GridData d = new GridData(SWT.FILL, SWT.FILL, true, true, 1,1);
natTable.setLayoutData(d);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultTreeLayerConfiguration(treeLayer));
natTable.setTheme(modernTheme);
natTable.configure();
这也是主题配置:
public class ModernNatTableThemeConfiguration extends DefaultNatTableThemeConfiguration {
public ModernNatTableThemeConfiguration( Image imageRightUp, Image imageTreeRightDown ){
TreeImagePainter treeImagePainter = new TreeImagePainter(
false,
imageRightUp, imageTreeRightDown, null); //$NON-NLS-1$//$NON-NLS-2$
this.treeStructurePainter = new BackgroundPainter(new PaddingDecorator(
new IndentedTreeImagePainter(10, null, CellEdgeEnum.LEFT,
treeImagePainter, false, 2, true), 0, 5, 0, 5, false));
TreeImagePainter treeSelectionImagePainter = new TreeImagePainter(
false,
imageRightUp, imageTreeRightDown, null); //$NON-NLS-1$//$NON-NLS-2$
this.treeStructureSelectionPainter = new BackgroundPainter(
new PaddingDecorator(new IndentedTreeImagePainter(10, null,
CellEdgeEnum.LEFT, treeSelectionImagePainter, false, 2,
true), 0, 5, 0, 5, false));
this.treeBgColor = GUIHelper.getColor(44, 104, 125);
this.treeFgColor = GUIHelper.getColor(44, 104, 125);
}
}
我想我们需要弄清楚这些条款。你想删除边框或网格线吗?因为你在样式配置中指定了边框,所以边框应该在那里。
如果你想摆脱网格线,你需要配置CellLayerPainter
。
可以这样做,例如:
configRegistry.registerConfigAttribute(
CellConfigAttributes.RENDER_GRID_LINES,
Boolean.FALSE);
顺便说一句,像您在代码中所做的那样直接修改 ConfigRegistry
不是一个好习惯。您应该创建一个 IConfiguration
(例如 AbstractRegistryConfiguration
)并将 IConfiguration
注册到您的 NatTable 实例。否则 NatTable#configure()
可能会在配置时覆盖您的更改。
此处解释如下:http://www.vogella.com/tutorials/NatTable/article.html#architecture_configuration