Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Click on empty row in a table
Click on empty row in a table [message #518961] Fri, 05 March 2010 15:11 Go to next message
Thomas Kratz is currently offline Thomas KratzFriend
Messages: 165
Registered: July 2009
Senior Member
HI, I try to detect a click on an empty row in a table in a platform independend way. When I look at the Table implementation I could aks the OS for the selection, but that would mean I have to do that platform dependent (which I want to avoid). Can anyone give me a hint how I could listen to such a click ?
Re: Click on empty row in a table [message #518973 is a reply to message #518961] Fri, 05 March 2010 15:22 Go to previous messageGo to next message
Thomas Kratz is currently offline Thomas KratzFriend
Messages: 165
Registered: July 2009
Senior Member
new MouseListener()
		{
			
			@Override
			public void mouseUp(MouseEvent e)
			{
				TableItem item = viewer.getTable().getItem(new Point(e.x,e.y));
				System.out.println(item); /is null
				
			}


already found "one" answer
Re: Click on empty row in a table [message #519343 is a reply to message #518973] Mon, 08 March 2010 14:52 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
That way should work, though it's generally suggested to listen on MouseDown
instead of MouseUp. Are there cases where this approach doesn't do what you
want?

Grant


"Thomas Kratz" <eiswind@googlemail.com> wrote in message
news:hmr7k4$gb6$1@build.eclipse.org...
> new MouseListener()
> {
>
> @Override
> public void mouseUp(MouseEvent e)
> {
> TableItem item = viewer.getTable().getItem(new Point(e.x,e.y));
> System.out.println(item); /is null
>
> }
>
> already found "one" answer
Re: Click on empty row in a table [message #519345 is a reply to message #519343] Mon, 08 March 2010 15:01 Go to previous messageGo to next message
Thomas Kratz is currently offline Thomas KratzFriend
Messages: 165
Registered: July 2009
Senior Member
Its meaningful only with FULL_SELECTION otherwise the table rows that have romm left over beneath the columns also reply with null on getItem(); and thats confusing to ths user (and me Smile
Re: Click on empty row in a table [message #519404 is a reply to message #519345] Mon, 08 March 2010 17:50 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
I think brute force is the way to go then:

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setBounds(10,10,400,400);
shell.setLayout(new FillLayout());
final Table table = new Table (shell, SWT.V_SCROLL);
for (int i = 0; i < 9; i++) {
new TableItem(table, SWT.NONE).setText("item " + i);
}
table.addListener(SWT.MouseDown, new Listener() { // <---
public void handleEvent(Event event) {
Rectangle bounds = table.getItem(table.getItemCount() -
1).getBounds();
if (bounds.y + bounds.height < event.y) {
System.out.println("clicked below");
}
}
});
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

Grant


"Thomas Kratz" <eiswind@googlemail.com> wrote in message
news:hn33fk$aib$1@build.eclipse.org...
> Its meaningful only with FULL_SELECTION otherwise the table rows that have
romm left over beneath the columns also reply with null on getItem(); and
thats confusing to ths user (and me :)
Previous Topic:Custom GUI builder in my RCP application
Next Topic:Filtering lines in StyledText
Goto Forum:
  


Current Time: Wed Aug 21 02:33:01 GMT 2019

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

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

Back to the top