Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Newb question using tabbing
Newb question using tabbing [message #462892] Thu, 20 October 2005 13:50 Go to next message
Sebastien is currently offline SebastienFriend
Messages: 20
Registered: July 2009
Junior Member
Hello, even if I'm getting the hack out of SWT, things still mesmerize me
like tabbing :



I might have a trivial problem, but it is one I'm fumbling to resolve and QA
tests are approaching. I have a specific tab order but suffice the user
clicks within a widget I don't want the tab order to stop to and tabbing
loops within that widget. Note of importance: I have many tab orders
avoiding tens of widgets within widgets. How can I get the focus back
following the tab order?



A Snippet is worth a thousand words J so I've joint it to this post. The
user mustn't click within the text widget or else tab order is ruined.



import org.eclipse.swt.SWT;

import org.eclipse.swt.widgets.*;

import org.eclipse.swt.widgets.Button;

import org.eclipse.swt.widgets.Composite;

import org.eclipse.swt.widgets.Text;

import org.eclipse.swt.layout.GridLayout;

import org.eclipse.swt.layout.RowLayout;



public class Tabbing {



private static Text text;

public static void main (String [] args) {

Display display = new Display ();

Shell shell = new Shell (display);

shell.setLayout (new RowLayout ());



final Composite composite = new Composite(shell, SWT.NONE);

composite.setLayout(new RowLayout());



Composite c1 = new Composite (composite, SWT.BORDER);

c1.setLayout (new RowLayout ());

Button b1 = new Button (c1, SWT.PUSH);

b1.setText ("B1");

Button b3 = new Button (c1, SWT.PUSH);

b3.setText ("B&3");



final Composite c1_1 = new Composite(composite, SWT.BORDER);

c1_1.setLayout(new RowLayout());



final Button b1_1 = new Button(c1_1, SWT.NONE);

b1_1.setText("B1");



final Button b3_1 = new Button(c1_1, SWT.NONE);

b3_1.setText("B&3");



Composite c4 = new Composite (composite, SWT.BORDER);

c4.setLayout(new GridLayout());

c4.setSize (32, 32);

Composite c5 = new Composite (c4, SWT.BORDER);

c5.setLayout(new GridLayout());



text = new Text(c5, SWT.RIGHT | SWT.BORDER);

text.setText("Hello");

Control [] list2 = new Control [] {c1, c1_1};

composite.setTabList(list2);



shell.pack ();

shell.open ();



while (!shell.isDisposed ()) {

if (!display.readAndDispatch ()) display.sleep ();

}

display.dispose ();

}

}
Re: Newb question using tabbing [message #462942 is a reply to message #462892] Fri, 21 October 2005 15:06 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Sebastien,

To override the default tabbing behaviour in this context you need to change
the focus explicitly. Adding the following to your example should help:

text.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_TAB_NEXT) {
b1.setFocus();
e.doit = false;
}
if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
b3_1.setFocus();
e.doit = false;
}
}
});

You say that your real case involves many more widgets. To handle this you
can either create an instance of this Travserse listener and hook it on all
of them (or possibly just the first/last ones?), or use
Display.addFilter(SWT.Traverse, new Listener...) to be notified of all
traverses, and for each, use getParent() repeatedly to walk up the widget
hierarchy to determine if the traversal is happening in a widget that is
within a good Composite or not.

Grant

"Sebastien" <freshtasty@hotmail.com> wrote in message
news:dj87b4$q9h$1@news.eclipse.org...
> Hello, even if I'm getting the hack out of SWT, things still mesmerize me
> like tabbing :
>
>
>
> I might have a trivial problem, but it is one I'm fumbling to resolve and
QA
> tests are approaching. I have a specific tab order but suffice the user
> clicks within a widget I don't want the tab order to stop to and tabbing
> loops within that widget. Note of importance: I have many tab orders
> avoiding tens of widgets within widgets. How can I get the focus back
> following the tab order?
>
>
>
> A Snippet is worth a thousand words J so I've joint it to this post. The
> user mustn't click within the text widget or else tab order is ruined.
>
>
>
> import org.eclipse.swt.SWT;
>
> import org.eclipse.swt.widgets.*;
>
> import org.eclipse.swt.widgets.Button;
>
> import org.eclipse.swt.widgets.Composite;
>
> import org.eclipse.swt.widgets.Text;
>
> import org.eclipse.swt.layout.GridLayout;
>
> import org.eclipse.swt.layout.RowLayout;
>
>
>
> public class Tabbing {
>
>
>
> private static Text text;
>
> public static void main (String [] args) {
>
> Display display = new Display ();
>
> Shell shell = new Shell (display);
>
> shell.setLayout (new RowLayout ());
>
>
>
> final Composite composite = new Composite(shell, SWT.NONE);
>
> composite.setLayout(new RowLayout());
>
>
>
> Composite c1 = new Composite (composite, SWT.BORDER);
>
> c1.setLayout (new RowLayout ());
>
> Button b1 = new Button (c1, SWT.PUSH);
>
> b1.setText ("B1");
>
> Button b3 = new Button (c1, SWT.PUSH);
>
> b3.setText ("B&3");
>
>
>
> final Composite c1_1 = new Composite(composite, SWT.BORDER);
>
> c1_1.setLayout(new RowLayout());
>
>
>
> final Button b1_1 = new Button(c1_1, SWT.NONE);
>
> b1_1.setText("B1");
>
>
>
> final Button b3_1 = new Button(c1_1, SWT.NONE);
>
> b3_1.setText("B&3");
>
>
>
> Composite c4 = new Composite (composite, SWT.BORDER);
>
> c4.setLayout(new GridLayout());
>
> c4.setSize (32, 32);
>
> Composite c5 = new Composite (c4, SWT.BORDER);
>
> c5.setLayout(new GridLayout());
>
>
>
> text = new Text(c5, SWT.RIGHT | SWT.BORDER);
>
> text.setText("Hello");
>
> Control [] list2 = new Control [] {c1, c1_1};
>
> composite.setTabList(list2);
>
>
>
> shell.pack ();
>
> shell.open ();
>
>
>
> while (!shell.isDisposed ()) {
>
> if (!display.readAndDispatch ()) display.sleep ();
>
> }
>
> display.dispose ();
>
> }
>
> }
>
>
>
>
>
>
>
>
>
>
>
>
Re: Newb question using tabbing [message #462952 is a reply to message #462942] Fri, 21 October 2005 18:47 Go to previous message
Sebastien is currently offline SebastienFriend
Messages: 20
Registered: July 2009
Junior Member
Thank you, it's sincerely appreciated :-) I will look into your advices.
Previous Topic:Saving and retrieving StyledText to/from database
Next Topic:Invalid thread access
Goto Forum:
  


Current Time: Thu Apr 25 00:56:29 GMT 2024

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

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

Back to the top