Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to suppress visual selection and mouse-over in swt.widgets.Table?
How to suppress visual selection and mouse-over in swt.widgets.Table? [message #837396] Thu, 05 April 2012 16:13 Go to next message
David Hanney is currently offline David HanneyFriend
Messages: 2
Registered: April 2012
Junior Member
How do I get rid of org.eclipse.swt.widgets.Table row highlighting on both select and mouse-over?

I want my red and blue backgrounds maintained throughout the table no matter what the user does with the mouse.

This is as near as I can get
(and it is nowhere near)
so any help would be gladly received.

(Windows 7 and swt-3.8M5-win32-win32-x86_64)

Thanks in advance!

David
p.s. I've tried variations on handling SWT.EraseItem as discussed in
"Eclipse Corner Article: Custom Drawing Table and Tree Items".




import java.io.IOException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class TablePain {
	public static void main(String[] args) throws IOException {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

		final Color red = display.getSystemColor(SWT.COLOR_RED);
		final Color blue = display.getSystemColor(SWT.COLOR_BLUE);

		final Table table = new Table(shell, SWT.H_SCROLL | SWT.VIRTUAL
				| SWT.FULL_SELECTION);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		table.setItemCount(1000);

		for (int x = 0; x < 3; x++) {
			final TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText("col" + x);
			column.setWidth(100);
			column.setMoveable(true);
		}

		table.addListener(SWT.SetData, new Listener() {
			public void handleEvent(Event e) {
				TableItem item = (TableItem) e.item;
				int y = table.indexOf(item);
				item.setText(new String[] { "data0", "data1", "data2" });
				for (int x = 0; x < 3; x++) {
					boolean isRed = ((x^y)&1)==0;
					item.setBackground(x, isRed ? red : blue);
				}
			}
		});

		table.addListener(SWT.EraseItem, new Listener() {
			public void handleEvent(Event event) {
				// Selection:
				event.detail &= ~SWT.SELECTED;
				// Expect: selection now has no visual effect.
				// Actual: selection remains but changes from light blue to white.

				// MouseOver:
				event.detail &= ~SWT.HOT;
				// Expect: mouse over now has no visual effect.
				// Actual: behavior remains unchanged.
			}
		});

		shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

[Updated on: Tue, 10 April 2012 09:43]

Report message to a moderator

Re: How to suppress visual selection and mouse-over in swt.widgets.Table? [message #878387 is a reply to message #837396] Tue, 29 May 2012 07:55 Go to previous messageGo to next message
David Hanney is currently offline David HanneyFriend
Messages: 2
Registered: April 2012
Junior Member
Changing my SWT.EraseItem listener like this ...

		table.addListener(SWT.EraseItem, new Listener() {
			public void handleEvent(Event event) {
				// Selection:
				event.detail &= ~SWT.SELECTED;
				// Expect: selection now has no visual effect.
				// Actual: selection remains but changes from light blue to white.

				// MouseOver:
				event.detail &= ~SWT.HOT;
				// Expect: mouse over now has no visual effect.
				// Actual: behavior remains unchanged.
				
		        GC gc = event.gc;
		        TableItem item = (TableItem) event.item;
		        gc.setBackground(item.getBackground(event.index));
		        gc.fillRectangle(event.x, event.y, event.width, event.height);

			}
		});


... get's me most of the way there.

There are still some thin dotted lines indicating selection. Here we see the first row selected:

index.php/fa/9936/0/

I can live with this but I'd rather there was no visual indication whatsoever.

All ideas gratefully received.

David
  • Attachment: swt-shot.png
    (Size: 24.05KB, Downloaded 3801 times)

[Updated on: Tue, 29 May 2012 07:55]

Report message to a moderator

Re: How to suppress visual selection and mouse-over in swt.widgets.Table? [message #878694 is a reply to message #878387] Tue, 29 May 2012 18:40 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Adding the below line to your EraseItem listener will take care of this
last bit:

event.detail &= ~SWT.FOCUSED;

Grant


On 5/29/2012 3:55 AM, David Hanney wrote:
> Changing my SWT.EraseItem listener like this ...
>
>
> table.addListener(SWT.EraseItem, new Listener() {
> public void handleEvent(Event event) {
> // Selection:
> event.detail&= ~SWT.SELECTED;
> // Expect: selection now has no visual effect.
> // Actual: selection remains but changes from light blue to white.
>
> // MouseOver:
> event.detail&= ~SWT.HOT;
> // Expect: mouse over now has no visual effect.
> // Actual: behavior remains unchanged.
>
> GC gc = event.gc;
> TableItem item = (TableItem) event.item;
> gc.setBackground(item.getBackground(event.index));
> gc.fillRectangle(event.x, event.y, event.width, event.height);
>
> }
> });
>
>
> .. get's me most of the way there.
>
> There are still some thin dotted lines indicating selection:
>
>
>
> I can live with this but I'd rather there was no visual indication whatsoever.
>
> All ideas gratefully received.
>
> David
Re: How to suppress visual selection and mouse-over in swt.widgets.Table? [message #1327472 is a reply to message #878694] Fri, 02 May 2014 07:07 Go to previous message
sushanth kumar is currently offline sushanth kumarFriend
Messages: 1
Registered: May 2014
Junior Member
this code

event.detail&= ~SWT.SELECTED;

is working fine in the windows platform

but in mac os x the application is going to hanging and not responding after wards

please check the attached file
Previous Topic:Backport Firefox 24 integration to 3.X
Next Topic:XPCOM error 0x80040111 - XULrunner 24, SWT 4.4M6, OSX
Goto Forum:
  


Current Time: Thu Apr 25 00:28:45 GMT 2024

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

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

Back to the top