Skip to main content



      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 10:11 Go to next message
Eclipse UserFriend
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 10:22 Go to previous messageGo to next message
Eclipse UserFriend
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 09:52 Go to previous messageGo to next message
Eclipse UserFriend
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 10:01 Go to previous messageGo to next message
Eclipse UserFriend
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 12:50 Go to previous message
Eclipse UserFriend
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: Fri Jul 04 22:10:48 EDT 2025

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

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

Back to the top