Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Virtual table problems
Virtual table problems [message #462360] Tue, 11 October 2005 09:44 Go to next message
Robert Bacs is currently offline Robert Bacs
Messages: 165
Registered: July 2009
Senior Member
Hi,

I'm using a Table control with SWT.VIRTUAL flag, all items have an image
(100x90 pixels), now the problem is if the user keeps the page down button
down after a while there is no image displayed for table items. There is no
error message with no more handles or out of memory.
Below is a snippet based on this problem, of course the image size is
smaller.

Best regards,
Boby

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

public class TableTest {

static final int COUNT = 50000;
private static Table table;

public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.VERTICAL));
table = new Table(shell, SWT.VIRTUAL | SWT.BORDER);
table.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
final int index = table.indexOf (item);

Thread thread = new Thread() {
public void run() {
PaletteData paletteData = new PaletteData(new RGB[] {
new RGB(255, 0, 0), new RGB(0, 255, 0) });
ImageData imageData = new ImageData(50, 50, 1, paletteData);
for (int x = 11; x < 35; x++) {
for (int y = 11; y < 35; y++) {
imageData.setPixel(x, y, 1);
}
}
setImage(index, imageData);
}
};
thread.start();
}
});
table.setLayoutData(new RowData(200, 200));
Button button = new Button(shell, SWT.PUSH);
button.setText("Add Items");
final Label label = new Label(shell, SWT.NONE);
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
long t1 = System.currentTimeMillis();
table.setItemCount(COUNT);
long t2 = System.currentTimeMillis();
label.setText("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms)");
shell.layout();
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

/**
*
* @param index
* @param imageData
*/
private static void setImage(final int index, final ImageData imageData) {
table.getDisplay().asyncExec(new Runnable(){
public void run() {
TableItem item = table.getItem(index);
item.setImage(new Image(table.getDisplay(), imageData));
item.setText("" + index);
}
});
}
}
Re: Virtual table problems [message #463375 is a reply to message #462360] Fri, 04 November 2005 14:09 Go to previous message
Steve Northover is currently offline Steve Northover
Messages: 1636
Registered: July 2009
Senior Member
This is happening because you are leaking the image and Windows runs out of
resources.

"Robert Bacs" <boby@zerosoft.ro> wrote in message
news:digfj8$cb6$1@news.eclipse.org...
> Hi,
>
> I'm using a Table control with SWT.VIRTUAL flag, all items have an image
> (100x90 pixels), now the problem is if the user keeps the page down button
> down after a while there is no image displayed for table items. There is
no
> error message with no more handles or out of memory.
> Below is a snippet based on this problem, of course the image size is
> smaller.
>
> Best regards,
> Boby
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.Image;
> import org.eclipse.swt.graphics.ImageData;
> import org.eclipse.swt.graphics.PaletteData;
> import org.eclipse.swt.graphics.RGB;
> import org.eclipse.swt.layout.RowData;
> import org.eclipse.swt.layout.RowLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Event;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Listener;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Table;
> import org.eclipse.swt.widgets.TableItem;
>
> public class TableTest {
>
> static final int COUNT = 50000;
> private static Table table;
>
> public static void main(String[] args) {
> Display display = new Display();
> final Shell shell = new Shell(display);
> shell.setLayout(new RowLayout(SWT.VERTICAL));
> table = new Table(shell, SWT.VIRTUAL | SWT.BORDER);
> table.addListener(SWT.SetData, new Listener() {
> public void handleEvent(Event event) {
> TableItem item = (TableItem) event.item;
> final int index = table.indexOf (item);
>
> Thread thread = new Thread() {
> public void run() {
> PaletteData paletteData = new PaletteData(new RGB[] {
> new RGB(255, 0, 0), new RGB(0, 255, 0) });
> ImageData imageData = new ImageData(50, 50, 1, paletteData);
> for (int x = 11; x < 35; x++) {
> for (int y = 11; y < 35; y++) {
> imageData.setPixel(x, y, 1);
> }
> }
> setImage(index, imageData);
> }
> };
> thread.start();
> }
> });
> table.setLayoutData(new RowData(200, 200));
> Button button = new Button(shell, SWT.PUSH);
> button.setText("Add Items");
> final Label label = new Label(shell, SWT.NONE);
> button.addListener(SWT.Selection, new Listener() {
> public void handleEvent(Event event) {
> long t1 = System.currentTimeMillis();
> table.setItemCount(COUNT);
> long t2 = System.currentTimeMillis();
> label.setText("Items: " + COUNT + ", Time: " + (t2 - t1) + "
(ms)");
> shell.layout();
> }
> });
> shell.pack();
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> /**
> *
> * @param index
> * @param imageData
> */
> private static void setImage(final int index, final ImageData imageData)
{
> table.getDisplay().asyncExec(new Runnable(){
> public void run() {
> TableItem item = table.getItem(index);
> item.setImage(new Image(table.getDisplay(), imageData));
> item.setText("" + index);
> }
> });
> }
> }
>
>
>
>
Previous Topic:How to stop Text from resizing ?
Next Topic:Is there a way to view all widget events?
Goto Forum:
  


Current Time: Fri Aug 22 15:40:58 EDT 2014

Powered by FUDForum. Page generated in 0.01901 seconds