Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » FocusListener and mouse
FocusListener and mouse [message #461295] Tue, 20 September 2005 13:18 Go to next message
arne anka is currently offline arne ankaFriend
Messages: 133
Registered: July 2009
Senior Member
hi,
i added a FocusListener to a couple of Text-fields to make the content
highlight when the Text gains the focus.

FocusAdapter fa=new FocusAdapter(){
public void focusGained(FocusEvent e){
Text t=(Text)e.widget;
t.selectAll();
}
};

it works well, if i use the TAB-key to go from Text to Text, it does not
really work when using the mouse:
- i click into (mousebutton down) and the content is highlighted
- i release the mousebutton (mousebutton up) and the selection is gone.

how do i prevent the misbehaviour on mousebutton up?
any help appreciated.
Re: FocusListener and mouse [message #461301 is a reply to message #461295] Tue, 20 September 2005 14:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ddana78ar.yahoo.com.ar

the tab key, works with the traverseListener.
For your problem with the mouse, I think that you can set:
e.doIt = false;
if you want to stop the event after you have highlighted the text, or into the mouseUp event catching.
Re: FocusListener and mouse [message #461302 is a reply to message #461301] Tue, 20 September 2005 14:41 Go to previous messageGo to next message
arne anka is currently offline arne ankaFriend
Messages: 133
Registered: July 2009
Senior Member
> For your problem with the mouse, I think that you can set:
> e.doIt = false;

FocusEvent does not have doit :-(

but i found my thoughts overly complex: at least for stw/gtk (i use it in
an rcp-application) highlighting of content while getting there with TAB
seems to be the default. so i removed the FocusListener and added a
MouseLsitener with exactly the same functionality ... eh voila.

regarding TraversalListener (i still have problems with the term
Traversal): is that listener responsible for creating a chain like "if the
user presses TAB go to widget a, next TAB got tow widget b, next TAB
widget c" and so on?

regards
Re: FocusListener and mouse [message #461306 is a reply to message #461302] Tue, 20 September 2005 15:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ddana78ar.yahoo.com.ar

> regarding TraversalListener (i still have problems
> with the term
> Traversal): is that listener responsible for creating
> a chain like "if the
> user presses TAB go to widget a, next TAB got tow
> widget b, next TAB
> widget c" and so on?
yes, its by default. But if you want to cange that order, you have to create a collection with the widgets and "force" the next.
Re: FocusListener and mouse [message #461308 is a reply to message #461306] Tue, 20 September 2005 15:46 Go to previous messageGo to next message
arne anka is currently offline arne ankaFriend
Messages: 133
Registered: July 2009
Senior Member
> yes, its by default. But if you want to cange that order, you have to
> create a collection with the widgets and "force" the next.

do you know a code snippet or a tutorila showing that?

regards
Re: FocusListener and mouse [message #461310 is a reply to message #461308] Tue, 20 September 2005 16:47 Go to previous message
Eclipse UserFriend
Originally posted by: ddana78ar.yahoo.com.ar

------=_Part_51_21678526.1127235016134
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

look at this.
regards
------=_Part_51_21678526.1127235016134
Content-Type: application/octet-stream; name=TraverseTestingDefault.java
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=TraverseTestingDefault.java

/*
* Created on 20-sep-2005
* by DDana
*/
package testing;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TraverseTestingDefault {

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FormLayout());

Text t1 = new Text(shell,SWT.BORDER);
t1.setText("t1");
Text t2 = new Text(shell,SWT.BORDER);
t2.setText("t2");
Text t3 = new Text(shell,SWT.BORDER);
t3.setText("t3");
Text t4 = new Text(shell,SWT.BORDER);
t4.setText("t4");

FormData data = new FormData();
data.width = 50;
data.top = new FormAttachment(0,0);
data.left = new FormAttachment(0,0);
t1.setLayoutData(data);
data = new FormData();
data.width = 50;
data.top = new FormAttachment(0,0);
data.left = new FormAttachment(t1,0);
t2.setLayoutData(data);
data = new FormData();
data.width = 50;
data.top = new FormAttachment(t1,0);
data.left = new FormAttachment(0,0);
t3.setLayoutData(data);
data = new FormData();
data.width = 50;
data.top = new FormAttachment(t1,0);
data.left = new FormAttachment(t3,0);
t4.setLayoutData(data);

FocusListener focusListener = new FocusListener() {
public void focusLost(FocusEvent e) {
}
public void focusGained(FocusEvent e) {
String text = ((Text)e.widget).getText();
((Text)e.widget).setSelection(0,text.length());
}
};
t1.addFocusListener(focusListener);
t2.addFocusListener(focusListener);
t3.addFocusListener(focusListener);
t4.addFocusListener(focusListener);


shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}

------=_Part_51_21678526.1127235016134
Content-Type: application/octet-stream; name=TraverseTestingForce.java
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=TraverseTestingForce.java

/*
* Created on 20-sep-2005
* by DDana
*/
package testing;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TraverseTestingForce {
private static Text t1,t2,t3,t4;

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FormLayout());
shell.setLocation(200,200);

t1 = new Text(shell,SWT.BORDER);
t1.setText("t1");
t2 = new Text(shell,SWT.BORDER);
t2.setText("t2");
t3 = new Text(shell,SWT.BORDER);
t3.setText("t3");
t4 = new Text(shell,SWT.BORDER);
t4.setText("t4");

FormData data = new FormData();
data.width = 50;
data.top = new FormAttachment(0,0);
data.left = new FormAttachment(0,0);
t1.setLayoutData(data);
data = new FormData();
data.width = 50;
data.top = new FormAttachment(0,0);
data.left = new FormAttachment(t1,0);
t2.setLayoutData(data);
data = new FormData();
data.width = 50;
data.top = new FormAttachment(t1,0);
data.left = new FormAttachment(0,0);
t3.setLayoutData(data);
data = new FormData();
data.width = 50;
data.top = new FormAttachment(t1,0);
data.left = new FormAttachment(t3,0);
t4.setLayoutData(data);

TraverseListener traverseListener = new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
nextWidget(e);
}
};
t1.addTraverseListener(traverseListener);
t2.addTraverseListener(traverseListener);
t3.addTraverseListener(traverseListener);
t4.addTraverseListener(traverseListener);

shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

protected static void nextWidget(TraverseEvent e) {
if (((Text)e.widget) == t2){
t4.setFocus();
t4.setSelection(0,t4.getText().length());
e.doit = false;
}
}
}

------=_Part_51_21678526.1127235016134--
Previous Topic:Swing (SWT_AWT) and focus management (tab) problem
Next Topic:SWT advanced graphics
Goto Forum:
  


Current Time: Mon Oct 23 13:47:22 GMT 2017

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

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