Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » JFace Table: getColumnImage always returns all black
JFace Table: getColumnImage always returns all black [message #449153] Tue, 18 January 2005 16:55 Go to next message
Eclipse UserFriend
There sure are a lot of us with table viewer questions.

We want to use getColumnImage to return an image which is generated on the
fly. This, we believe, will allow us to draw anything in any cell and
help us overcome various inadequacies in the tables.

For example, try to make the text in a cell left-justified when the
heading is centered. Or, achieve an Excel-like appearance with row header
"buttons" in the leftmost column.

So, it should be pretty easy, right? In the getColumnImage method of the
table's label provider, we should be able to create a new image, get a GC
for it, draw on it and then return it.

Our code looks like what's shown below. Anybody have a clue why it never
works? It always makes an all black rectangle. TIA, Bill.

=============================

public Image getColumnImage(Object element, int columnIndex) {
switch (columnIndex) {
case 1:
Display d = Display.getCurrent();
image = new Image(d, 35, 14);
GC gc = new GC(image);

image.setBackground(new Color(d, 0, 123,88));
gc.setBackground(d.getSystemColor(SWT.COLOR_RED));
gc.fillRectangle(0,0,34,14);
return image;
default:
return null;
}
}
Re: JFace Table: getColumnImage always returns all black [message #449185 is a reply to message #449153] Tue, 18 January 2005 19:30 Go to previous message
Eclipse UserFriend
Bill Ewing wrote:

> There sure are a lot of us with table viewer questions.

> We want to use getColumnImage to return an image which is generated on the
> fly. This, we believe, will allow us to draw anything in any cell and
> help us overcome various inadequacies in the tables.

> For example, try to make the text in a cell left-justified when the
> heading is centered. Or, achieve an Excel-like appearance with row header
> "buttons" in the leftmost column.

> So, it should be pretty easy, right? In the getColumnImage method of the
> table's label provider, we should be able to create a new image, get a GC
> for it, draw on it and then return it.

> Our code looks like what's shown below. Anybody have a clue why it never
> works? It always makes an all black rectangle. TIA, Bill.

> =============================

> public Image getColumnImage(Object element, int columnIndex) {
> switch (columnIndex) {
> case 1:
> Display d = Display.getCurrent();
> image = new Image(d, 35, 14);
> GC gc = new GC(image);

> image.setBackground(new Color(d, 0, 123,88));
> gc.setBackground(d.getSystemColor(SWT.COLOR_RED));
> gc.fillRectangle(0,0,34,14);
> return image;
> default:
> return null;
> }
> }


OK, to answer my own question, the thing that kills the above code is the
lack of "gc.dispose" at the end.
Previous Topic:Auto-sizing table columns
Next Topic:RichText in SWT?
Goto Forum:
  


Current Time: Thu Jul 03 12:30:02 EDT 2025

Powered by FUDForum. Page generated in 0.03364 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top