tree.setLinesVisible(true)
on these systems, but it also won't draw vertical lines, which I need.I think you can do this using owner draw. Use this snippet as starting point, and exchange the EraseItem
event handler with this:
public void handleEvent( Event event ) {
event.detail &= ~SWT.HOT;
GC gc = event.gc;
Rectangle area = table.getClientArea();
/*
* If you wish to paint the selection beyond the end of
* last column, you must change the clipping region.
*/
int columnCount = table.getColumnCount();
if ( event.index == columnCount - 1 || columnCount == 0 ) {
int width = area.x + area.width - event.x;
if ( width > 0 ) {
Region region = new Region();
gc.getClipping(region);
region.add(event.x, event.y, width, event.height);
gc.setClipping(region);
region.dispose();
}
}
gc.setAdvanced(true);
if ( gc.getAdvanced() ) gc.setAlpha(127);
Rectangle rect = event.getBounds();
Color background = gc.getBackground();
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillRectangle(0, rect.y, 500, rect.height);
// restore colors for subsequent drawing
gc.setBackground(background);
}
Should work on GTK (which is the linux window manager SWT uses) and with Trees
, haven't tried it though.
Since owner draw is expensive I strongly suggest to add such a event handler for GTK:
if(SWT.getPlatform().equals("gtk")){ ... }
But the whole point of SWT is having native drawing. This improves the user acceptance of your software, because users feel "at home". Maybe you can design a way, where you don't have to take away the alternating background for GTK users.
精彩评论