[GTK3] images are cropped and/or not displayed in Tree with SWT.VIRTUAL
Describe the bug
Images in a tree with SWT.VIRTUAL often displayed as cropped or not shown at all.
Example 1:
Start the snippet below and press the following buttons: [2,1], then [3,2] and finally [1,0].
This is what I get: image for [3,2] is cropped, image for [1,0] isn't shown:
Example 2:
Start the snippet below and do the following:
- press button
[32,1] - scroll the content of the tree down to show
[32,1] - press buttons
[33,2]and[31,0]
This is what I get: images for [31,0], [32,1] and [33,2]are cropped:
To Reproduce
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class SetImage_TreeVirtual {
private Display display;
private Shell shell;
private Composite buttonBox;
private Tree tree;
private Image[][] images = new Image[50][3];
public static void main (String[] args) {
new SetImage_TreeVirtual ().run ();
}
void run () {
display = new Display ();
shell = new Shell (display);
shell.setText (getClass ().getSimpleName ());
shell.setLayout (new GridLayout ());
buttonBox = new Composite (shell, 0);
buttonBox.setLayout (new FillLayout ());
createSetImageButton (1, 0, 20, display.getSystemColor (SWT.COLOR_RED));
createSetImageButton (2, 1, 40, display.getSystemColor (SWT.COLOR_GREEN));
createSetImageButton (3, 2, 60, display.getSystemColor (SWT.COLOR_BLUE));
buttonBox = new Composite (shell, 0);
buttonBox.setLayout (new FillLayout ());
createSetImageButton (31, 0, 20, display.getSystemColor (SWT.COLOR_CYAN));
createSetImageButton (32, 1, 40, display.getSystemColor (SWT.COLOR_BLACK));
createSetImageButton (33, 2, 60, display.getSystemColor (SWT.COLOR_MAGENTA));
tree = new Tree (shell, SWT.VIRTUAL);
tree.setHeaderVisible (true);
tree.setLayoutData (new GridData (GridData.FILL_BOTH));
for (int i = 1; i <= 3; i++) {
var column = new TreeColumn (tree, SWT.LEFT);
column.setText ("Column " + i);
column.setWidth (200);
}
tree.addListener (SWT.SetData, e -> {
TreeItem item = (TreeItem) e.item;
var row = tree.indexOf (item);
for (var col = 0; col < 3; col++) {
item.setText (col, "[" + row + "," + col + "]");
item.setImage (col, images[row][col]);
}
});
tree.setItemCount (50);
shell.setSize (700, 600);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) {
display.sleep ();
}
}
display.dispose ();
}
private void createSetImageButton (int row, int col, int imageSize, Color imageColor) {
var button = new Button (buttonBox, SWT.PUSH);
var image = createImage (imageSize, imageColor);
button.setImage (image);
button.setText ("[" + row + "," + col + "]");
button.addListener (SWT.Selection, e -> {
images[row][col] = (images[row][col] == null) ? image : null;
tree.clear (row, false);
});
}
private Image createImage (int imageSize, Color color) {
var image = new Image (display, imageSize, imageSize);
var gc = new GC (image);
gc.setForeground (color);
gc.setBackground (display.getSystemColor (SWT.COLOR_WHITE));
gc.setLineWidth (5);
gc.fillRectangle (0, 0, imageSize, imageSize);
gc.drawRectangle (0, 0, imageSize - 1, imageSize - 1);
gc.dispose ();
return image;
}
}
Expected behavior Images should be shown and should not be cropped.
Screenshots See above.
Environment:
- Select the platform(s) on which the behavior is seen:
-
- [ ] All OS
-
- [ ] Windows
-
- [x] Linux
-
- [ ] macOS
-
Additional OS info (e.g. OS version, Linux Desktop, etc)
Ubuntu 24.04.1 LTS Windowing System x11 X.Org version: 21.1.11 XFCE 4.18 GTK 3.24.41 -
JRE/JDK version OpenJDK 64-Bit Server VM (build 17.0.13+11-Ubuntu-2ubuntu124.04, mixed mode, sharing)
Version since SWT 4.964
Workaround (or) Additional context Sometimes the snippet may crash because of #678
Hi, I am also seeing the same issue with below environment.
Environment Description: Ubuntu 24.04 LTS XDG_SESSION_TYPE=wayland
Eclipse SDK Version: 2025-03 (4.35) Build id: I20250108-1800 OS: Linux, v.6.8.0-51-generic, x86_64 / gtk 3.24.41 Java vendor: Oracle Corporation Java runtime version: 23+36-2368 Java version: 23
Let me try your pr now.