Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » MeasureItem event listener problem on Windows 7
MeasureItem event listener problem on Windows 7 [message #734048] Thu, 06 October 2011 14:00 Go to next message
H.ORTIZ  is currently offline H.ORTIZ Friend
Messages: 22
Registered: July 2009
Junior Member
Hi,

I added a MeasureItem event listener to a virtual table.
It works fine on Linux (SUSE 11) but it runs into an infinite loop on Windows 7.

The snippet below shows the problem (I modified the class Snippet144 to add a MeasureItem event listener). Have I done something wrong ?


package org.eclipse.swt.snippets;

import org.eclipse.swt.SWT;
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 Snippet144 {
	static final int COUNT = 100;

	public static void main(String[] args) {
		Display display = new Display ();
		final Shell shell = new Shell (display);
		shell.setLayout (new RowLayout (SWT.VERTICAL));
		final Table table = new Table (shell, SWT.VIRTUAL | SWT.BORDER);
		table.addListener (SWT.SetData, new Listener () {
			public void handleEvent (Event event) {
				TableItem item = (TableItem) event.item;
				int index = table.indexOf (item);
				item.setText ("Item " + index);
				System.out.println (item.getText ());
			}
		});
		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 ();
			}
		});
		
		
		table.addListener(SWT.MeasureItem, new Listener() {
			
			public void handleEvent(Event event) {
				System.out.println("measure");
				event.height += 1;
			}
		});
		
		shell.pack ();
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}

}



Re: MeasureItem event listener problem on Windows 7 [message #734400 is a reply to message #734048] Fri, 07 October 2011 15:54 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
The event.height += 1 is the cause, it should just set event.height to
the final desired item height. The frequency of SWT.MeasureItem
invocations is not spec'd, and a difference here is why you're seeing
the behaviour difference between win32 and gtk. The Table on win32 will
(at least temporarily) stop calling MeasureItem for an item once there
is an invocation for which event.height is not changed.

Grant


On 10/6/2011 10:00 AM, H.ORTIZ wrote:
> import org.eclipse.swt.SWT;
> 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 Snippet144 {
> static final int COUNT = 100;
>
> public static void main(String[] args) {
> Display display = new Display ();
> final Shell shell = new Shell (display);
> shell.setLayout (new RowLayout (SWT.VERTICAL));
> final Table table = new Table (shell, SWT.VIRTUAL | SWT.BORDER);
> table.addListener (SWT.SetData, new Listener () {
> public void handleEvent (Event event) {
> TableItem item = (TableItem) event.item;
> int index = table.indexOf (item);
> item.setText ("Item " + index);
> System.out.println (item.getText ());
> }
> });
> 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 ();
> }
> });
>
>
> table.addListener(SWT.MeasureItem, new Listener() {
>
> public void handleEvent(Event event) {
> System.out.println("measure");
> event.height += 1;
> }
> });
>
> shell.pack ();
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
>
> }
Previous Topic:OSX: HotKeys not working
Next Topic:Scrolling problem with flat look and Windows XP Theme
Goto Forum:
  


Current Time: Wed Apr 24 23:11:02 GMT 2024

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

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

Back to the top