|
|
Re: How to set background image for whole nattable [message #1384115 is a reply to message #1384102] |
Wed, 28 May 2014 07:11 |
Dirk Fauth Messages: 2902 Registered: July 2012 |
Senior Member |
|
|
Just tried and setBackgroundImage() does not work that simply.
So for a different background color you want to use for the whole NatTable, you can try this code:
final NatTable natTable = new NatTable(
parent, bodyDataLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
cellPainter = new TextPainter(false, false);
}
});
natTable.configure();
natTable.setBackground(GUIHelper.COLOR_YELLOW);
For the background image you need to set a different NatLayerPainter, as the default one is cleaning up the background by always painting the background color.
In that case this code should help:
final NatTable natTable = new NatTable(
parent bodyDataLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
cellPainter = new TextPainter(false, false);
}
});
natTable.configure();
natTable.setBackgroundImage(new Image(Display.getCurrent(), "C:\\Daten\\dirk_fauth.jpg"));
natTable.setLayerPainter(new NatLayerPainter(natTable) {
@Override
protected void paintBackground(ILayer natLayer, GC gc, int xOffset,
int yOffset, Rectangle rectangle,
IConfigRegistry configRegistry) {
//do nothing to avoid overpainting the background image
}
});
|
|
|
Re: How to set background image for whole nattable [message #1384170 is a reply to message #1384115] |
Wed, 28 May 2014 10:03 |
jacky gao Messages: 4 Registered: May 2014 |
Junior Member |
|
|
Thanks for your help,I have already realized to set background image for whole nattable.
My code:
natTable.setLayerPainter(new NatLayerPainter(natTable){
@Override
protected void paintBackground(ILayer natLayer, GC gc, int xOffset,int yOffset, Rectangle rectangle,IConfigRegistry configRegistry) {
super.paintBackground(natLayer, gc, xOffset, yOffset, rectangle, configRegistry);
String path=editor.report.getBackgroundImage();
if(path!=null){
try{
Image bgImg=Activator.getImage(path, true);
IPreferenceStore store=Utils.getReportPreferenceStore();
int width=store.getInt(RowHeaderLayerStack.ROW_HEADER_WIDTH);
gc.drawImage(bgImg, rectangle.x+width, rectangle.y+DataLayer.DEFAULT_ROW_HEIGHT);
}catch(Exception ex){
ex.printStackTrace();
}
}
}
});
|
|
|
|
Powered by
FUDForum. Page generated in 0.03018 seconds