Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Capturing key event F5 in TabFolder
Capturing key event F5 in TabFolder [message #445173] Wed, 27 October 2004 11:56 Go to next message
Eclipse UserFriend
Originally posted by: nvragh.yahoo.co.uk

This question is somewhat related to my previous post.

I have an UI which has a TabFolder with three tab items. I want to capture
the keyevent F5, if the user presses it and do some UI work. I have added
listeners for event F5, but, the handleEvent method is not being called.
Can anyone pls. tell me why? (Pasted the code below). Searched this forum
for the issue, but not very clear abt solution given for somewhat related
problem like this as i am new to SWT.

P.S: I don't want to add any Menu/MenuItem in the UI.

Code:
=====

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;

public class HelloWorld
{
private static Display display = null;

public static void main (String [] args)
{
display = new Display ();
Shell shell = new HelloWorld().open (display);
while (!shell.isDisposed ())
{
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

public Shell open (Display display)
{
final Shell shell = new Shell (display);
shell.setSize(200,200);
shell.setLayout(new GridLayout());

dummyTabImpl(shell);

addListeners(shell);

shell.open ();
return shell;
}

private void dummyTabImpl(Shell shell)
{
TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));

TabItem a = new TabItem(tabFolder, SWT.NONE | SWT.BORDER);
a.setText("A");
Composite aComposite = new Composite(tabFolder, SWT.NONE);
aComposite.setLayout(new GridLayout());
a.setControl(aComposite);

TabItem b = new TabItem(tabFolder, SWT.NONE | SWT.BORDER);
b.setText("B");
Composite bComposite = new Composite(tabFolder, SWT.NONE);
bComposite.setLayout(new GridLayout());
b.setControl(bComposite);

TabItem c = new TabItem(tabFolder, SWT.NONE | SWT.BORDER);
c.setText("C");
Composite cComposite = new Composite(tabFolder, SWT.NONE);
cComposite.setLayout(new GridLayout());
c.setControl(cComposite);
}

private void addListeners(Shell shell)
{
shell.addListener(SWT.F5, new Listener()
{
public void handleEvent(final Event event)
{
System.out.println("F5 in addListener");
}
});

/*
Tried this way also. But, didn't work
display.addFilter(SWT.F5, new Listener() {
public void handleEvent(Event e)
{
System.out.println("F5!!! ");
}
});
*/

/*
Tried this way also. But, didn't work
shell.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e)
{
int code = e.keyCode;
if(code == SWT.F5)
{
System.out.println("F5!!!!!!!");
}
}
});
*/
}
}

Thanks
Re: Capturing key event F5 in TabFolder [message #445178 is a reply to message #445173] Wed, 27 October 2004 14:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aflem80.yahoomail.com

Ran your code and found one thing. If i press 'F2' after pressing 'Tab'
key, it's working. So, only the focus is problem. If you set the focus
properly, it will work.

-Andrew Fleming.

nvragh wrote:

> This question is somewhat related to my previous post.

> I have an UI which has a TabFolder with three tab items. I want to capture
> the keyevent F5, if the user presses it and do some UI work. I have added
> listeners for event F5, but, the handleEvent method is not being called.
> Can anyone pls. tell me why? (Pasted the code below). Searched this forum
> for the issue, but not very clear abt solution given for somewhat related
> problem like this as i am new to SWT.

> P.S: I don't want to add any Menu/MenuItem in the UI.

> Code:
> =====

> import org.eclipse.swt.*;
> import org.eclipse.swt.widgets.*;
> import org.eclipse.swt.events.*;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;

> public class HelloWorld
> {
> private static Display display = null;

> public static void main (String [] args)
> {
> display = new Display ();
> Shell shell = new HelloWorld().open (display);
> while (!shell.isDisposed ())
> {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }

> public Shell open (Display display)
> {
> final Shell shell = new Shell (display);
> shell.setSize(200,200);
> shell.setLayout(new GridLayout());

> dummyTabImpl(shell);

> addListeners(shell);

> shell.open ();
> return shell;
> }

> private void dummyTabImpl(Shell shell)
> {
> TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
> tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));

> TabItem a = new TabItem(tabFolder, SWT.NONE | SWT.BORDER);
> a.setText("A");
> Composite aComposite = new Composite(tabFolder, SWT.NONE);
> aComposite.setLayout(new GridLayout());
> a.setControl(aComposite);

> TabItem b = new TabItem(tabFolder, SWT.NONE | SWT.BORDER);
> b.setText("B");
> Composite bComposite = new Composite(tabFolder, SWT.NONE);
> bComposite.setLayout(new GridLayout());
> b.setControl(bComposite);

> TabItem c = new TabItem(tabFolder, SWT.NONE | SWT.BORDER);
> c.setText("C");
> Composite cComposite = new Composite(tabFolder, SWT.NONE);
> cComposite.setLayout(new GridLayout());
> c.setControl(cComposite);
> }

> private void addListeners(Shell shell)
> {
> shell.addListener(SWT.F5, new Listener()
> {
> public void handleEvent(final Event event)
> {
> System.out.println("F5 in addListener");
> }
> });

> /*
> Tried this way also. But, didn't work
> display.addFilter(SWT.F5, new Listener() {
> public void handleEvent(Event e)
> {
> System.out.println("F5!!! ");
> }
> });
> */

> /*
> Tried this way also. But, didn't work
> shell.addKeyListener(new KeyAdapter(){
> public void keyPressed(KeyEvent e)
> {
> int code = e.keyCode;
> if(code == SWT.F5)
> {
> System.out.println("F5!!!!!!!");
> }
> }
> });
> */
> }
> }

> Thanks
Same KeyListener for All controls inside a TabItem [message #445181 is a reply to message #445178] Wed, 27 October 2004 15:08 Go to previous message
Eclipse UserFriend
Originally posted by: nvragh.yahoo.co.uk

Hi,

Thanks a lot for your reply and the problem got solved. But, If I add some
components inside a TabItem (say a Combo and a Table), the keylistener is
effective only if the focus is in the tab. But, if I select a row in the
table which I placed inside the TabItem and press F5, the event is not
firing.
Is there any way to achive it?

Thanks


Andrew Fleming wrote:

> Ran your code and found one thing. If i press 'F2' after pressing 'Tab'
> key, it's working. So, only the focus is problem. If you set the focus
> properly, it will work.

> -Andrew Fleming.

> nvragh wrote:

> > This question is somewhat related to my previous post.

> > I have an UI which has a TabFolder with three tab items. I want to capture
> > the keyevent F5, if the user presses it and do some UI work. I have added
> > listeners for event F5, but, the handleEvent method is not being called.
> > Can anyone pls. tell me why? (Pasted the code below). Searched this forum
> > for the issue, but not very clear abt solution given for somewhat related
> > problem like this as i am new to SWT.

> > P.S: I don't want to add any Menu/MenuItem in the UI.

> > Code:
> > =====

> > import org.eclipse.swt.*;
> > import org.eclipse.swt.widgets.*;
> > import org.eclipse.swt.events.*;
> > import org.eclipse.swt.layout.GridData;
> > import org.eclipse.swt.layout.GridLayout;

> > public class HelloWorld
> > {
> > private static Display display = null;

> > public static void main (String [] args)
> > {
> > display = new Display ();
> > Shell shell = new HelloWorld().open (display);
> > while (!shell.isDisposed ())
> > {
> > if (!display.readAndDispatch ()) display.sleep ();
> > }
> > display.dispose ();
> > }

> > public Shell open (Display display)
> > {
> > final Shell shell = new Shell (display);
> > shell.setSize(200,200);
> > shell.setLayout(new GridLayout());

> > dummyTabImpl(shell);

> > addListeners(shell);

> > shell.open ();
> > return shell;
> > }

> > private void dummyTabImpl(Shell shell)
> > {
> > TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
> > tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));

> > TabItem a = new TabItem(tabFolder, SWT.NONE | SWT.BORDER);
> > a.setText("A");
> > Composite aComposite = new Composite(tabFolder, SWT.NONE);
> > aComposite.setLayout(new GridLayout());
> > a.setControl(aComposite);

> > TabItem b = new TabItem(tabFolder, SWT.NONE | SWT.BORDER);
> > b.setText("B");
> > Composite bComposite = new Composite(tabFolder, SWT.NONE);
> > bComposite.setLayout(new GridLayout());
> > b.setControl(bComposite);

> > TabItem c = new TabItem(tabFolder, SWT.NONE | SWT.BORDER);
> > c.setText("C");
> > Composite cComposite = new Composite(tabFolder, SWT.NONE);
> > cComposite.setLayout(new GridLayout());
> > c.setControl(cComposite);
> > }

> > private void addListeners(Shell shell)
> > {
> > shell.addListener(SWT.F5, new Listener()
> > {
> > public void handleEvent(final Event event)
> > {
> > System.out.println("F5 in addListener");
> > }
> > });

> > /*
> > Tried this way also. But, didn't work
> > display.addFilter(SWT.F5, new Listener() {
> > public void handleEvent(Event e)
> > {
> > System.out.println("F5!!! ");
> > }
> > });
> > */

> > /*
> > Tried this way also. But, didn't work
> > shell.addKeyListener(new KeyAdapter(){
> > public void keyPressed(KeyEvent e)
> > {
> > int code = e.keyCode;
> > if(code == SWT.F5)
> > {
> > System.out.println("F5!!!!!!!");
> > }
> > }
> > });
> > */
> > }
> > }

> > Thanks
Previous Topic:How to output all classes including the SWT binary into a single JAR?
Next Topic:Rubber-banding
Goto Forum:
  


Current Time: Mon Nov 30 15:12:47 GMT 2020

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

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

Back to the top