Home » Eclipse Projects » Rich Client Platform (RCP) » Tableviewer column border/spacing problem
|
Re: Tableviewer column border/spacing problem [message #650071 is a reply to message #649815] |
Fri, 21 January 2011 15:47 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi,
This could be an swt bug. Does it work better for you if you draw each
cell's rectangle when you receive a PaintItem event for it (see
http://www.eclipse.org/articles/article.php?file=Article-Cus tomDrawingTableAndTreeItems/index.html )
?
Grant
"fran81" <francesca9999@gmail.com> wrote in message
news:ih9mre$o6g$1@news.eclipse.org...
> Hello,
>
> I have a tableviewer with a number of columns. I am trying to draw
> rectangles inside each cell of the tableviewer using
> gc.drawRectangle(x,y,width,height).
>
> It turns out that the rectangle are drawn at different coordinate values
> in the first column compared to columns n. 2, 3, etc.
>
> It looks like the rectangles in the first column are right-shifted by ~5px
> in the x axis. The code to draw rectangles in the table is the same,
> regardless of the column.
>
> I've tried to activate/deactivate the SWT.BORDER in the tableviewer styles
> but nothing changed...
>
> Is there a way to fix this behavior?
>
> Thanks,
> Francesca
|
|
| |
Re: Tableviewer column border/spacing problem [message #650581 is a reply to message #650424] |
Tue, 25 January 2011 15:37 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
The PaintItem listener is always added to a Table or Tree, but as it is
called for each of the table's cells you can do whatever you want to the
cell's content. The snippet below demonstrates drawing a border around each
cell's bounds and its image's bounds. The snippet uses only swt, but jface
exposes custom draw functionality in a similar way as demonstrated in
http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.jface. snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippe ts/viewers/Snippet010OwnerDraw.java?revision=1.8&view=ma rkup&pathrev=HEAD .
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,400,200);
shell.setLayout(new FillLayout());
Table table = new Table(shell, SWT.NONE);
Image image = new Image(display, 16, 16);
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gc.fillOval(0, 0, 15, 15);
gc.dispose();
new TableColumn(table, SWT.NONE).setWidth(90);
new TableColumn(table, SWT.NONE).setWidth(90);
new TableColumn(table, SWT.NONE).setWidth(90);
new TableColumn(table, SWT.NONE).setWidth(90);
for (int i = 0; i < 4; i++) {
TableItem item = new TableItem(table, SWT.NONE);
for (int j = 0; j < 4; j++) {
item.setText(j, i + "," + j);
item.setImage(j, image);
}
}
table.addListener(SWT.PaintItem, new Listener() {
public void handleEvent(Event event) {
TableItem item = (TableItem)event.item;
event.gc.setForeground(display.getSystemColor(SWT.COLOR_RED) );
event.gc.setLineStyle(SWT.LINE_DOT);
Rectangle rect = item.getImageBounds(event.index);
rect.height -= 1; rect.width -= 1;
event.gc.drawRectangle(rect);
event.gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE ));
rect = item.getBounds(event.index);
rect.height -= 1; rect.width -= 1;
event.gc.drawRectangle(rect);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
image.dispose();
display.dispose();
}
Grant
"fran81" <francesca9999@gmail.com> wrote in message
news:ihkjim$6p8$1@news.eclipse.org...
> HI Grant,
> thanks for your reply. How do I actually set the PaintItem?
>
> Now the cells of the tableviewer display Images that contain these
> rectangles. So the selection is programmatic.
>
> I find that I can add the PaintIem to a table for example, but how do I
> add it to an Image?
>
> Thanks,
> Francesca
|
|
|
Goto Forum:
Current Time: Fri Apr 26 08:24:29 GMT 2024
Powered by FUDForum. Page generated in 0.03223 seconds
|