Bug 270223 - Virtual Table with Images
Summary: Virtual Table with Images
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-27 04:11 EDT by Rudi Mising name CLA
Modified: 2019-09-06 15:30 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rudi Mising name CLA 2009-03-27 04:11:52 EDT
Hello,

I have discovered a strange behavior on virtual tables and scrollbars.

The following snippet opens a shell and shows a virtual table. No problem so far.

public class Main {

static int[] data = new int[0];

public static void main(String[] args) {

final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(300, 220);

final boolean showPic = false;

final List<String> values = new Vector<String>();
for (int i = 0; i < 10; i++) {

values.add("Value " + i);
}

final Table table = new Table(shell, SWT.BORDER | SWT.VIRTUAL);
table.setLinesVisible(true);
table.setHeaderVisible(true);

TableColumn column;

column = new TableColumn(table, SWT.NONE);
column.setText("Image");
column.setWidth(40);

column = new TableColumn(table, SWT.NONE);
column.setText("Value");
column.setWidth(100);

table.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event e) {
TableItem item = (TableItem) e.item;

Image image = getImage(display);

if (showPic)
item.setImage(0, image);
item.setText(1, "Item " + values.get(e.index));
}
});

table.setItemCount(values.size());
table.clearAll();

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

static Image getImage(Display display) {
    Image image = new Image(display, 24, 24);
    GC gc = new GC(image);
    gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
    gc.fillOval(0, 0, 24, 24);
    gc.setForeground(display.getSystemColor(SWT.COLOR_DARK_GREEN));
    gc.drawLine(0, 0, 24, 24);
    gc.drawLine(24, 0, 0, 24);
    gc.dispose();
    return image;
  }
}

If you change the line final boolean showPic = false;
to
final boolean showPic = true;
and run the snippet again, you will see, that the height of the table is bigger then the height of the shell, but the scrollbar dosn't appear. The scrollbar appears, when you resize the window for the first time.

I found out, that if you insert table.addListener(SWT.MeasureItem, new Listener() {

public void handleEvent(Event event) {

event.height = 30;
}
});

just after creating the table, the snippets works fine, that is to say the scrollbar is visible immediately.

I guess that the height of the image is not considered when the table is drawn for the first time and the sum of the heights of the rows without the images fit into the available space of the table, so the scrollbar is not shown.

I'm using eclipse 3.4.0

In the Eclipse-Forum they told me, that this could be a bug.

Thank you,
Rudi
Comment 1 Felipe Heidrich CLA 2009-03-27 11:54:06 EDT
This is a bug. You shouldn't need that SWT.MeasureItem.
Comment 2 Eclipse Webmaster CLA 2019-09-06 15:30:08 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.