Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » CTabItem not focusing as expected
CTabItem not focusing as expected [message #463440] Mon, 07 November 2005 09:32 Go to next message
Alex Malinovich is currently offline Alex MalinovichFriend
Messages: 5
Registered: July 2009
Junior Member
I'm having a problem with my CTabFolder not gaining and losing focus
"correctly". I'm trying to emulate the Eclipse editor behavior for the
tabs. The first problem is that accountTabs is losing focus to widgets
which are its children. I have a table with accountTabs set as its parent,
and it will actually take focus away from accountTabs.

The other problem is that once the focus is gone, the only way to get it
back is to click on the tab and then push Tab on my keyboard. Just
clicking on the tabs changes the active tab, but it does NOT generate a
focusGained event. Any help is greatly appreciated.

I'm creating the CTabFolder using the following:

final CTabFolder accountTabs = new CTabFolder(msgShell, SWT.TOP);
accountTabs.setSimple(false);
accountTabs.setBorderVisible(true);
accountTabs.setTabHeight(accountTabs.getTabHeight() + 5);

accountTabs.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
accountTabs.setSelectionForeground(
display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND));
accountTabs.setSelectionBackground(
new Color[]{display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND),
display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)} ,
new int[]{90}, true);
}
public void focusLost(FocusEvent e) {
accountTabs.setSelectionForeground(
display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND));
accountTabs.setSelectionBackground(
new Color[]
{display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_ GRADIENT),
display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)} , new
int[]{90}, true);
}
}
});
Re: CTabItem not focusing as expected [message #463458 is a reply to message #463440] Mon, 07 November 2005 15:29 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
The focus event is only sent when the folder itself gets focus. Typically,
you do not want the folder tabs to take focus because the action the user
wants to take after selecting a tab is to enter information in the contents
of the tab. Requiring a second click to get to the text field etc is
annoying to the user.

In your case, to change the colours of the tabs, try using the Activate and
Deactivate events as shown below:

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
Button b = new Button(shell, SWT.PUSH);
b.setText("Button 1");
final CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
CTabItem item = new CTabItem(folder, SWT.NONE);
item.setText("title for tab 1");
b = new Button(folder, SWT.PUSH);
b.setText("Button 2");
item.setControl(b);
item = new CTabItem(folder, SWT.NONE);
item.setText("title for tab 2");
b = new Button(folder, SWT.PUSH);
b.setText("Button 3");
item.setControl(b);
b = new Button(shell, SWT.PUSH);
b.setText("Button 4");

final Color titleFore =
display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND);
final Color titleBack =
display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
final Color titleBackGrad =
display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
final Color titleInactiveBackGrad =
display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_G RADIENT);
final Color titleInactiveBack =
display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND);

Listener listener = new Listener() {
public void handleEvent(Event e) {
switch (e.type) {
case SWT.Activate:
folder.setSelectionForeground(titleFore);
folder.setSelectionBackground(
new Color[]{titleBack, titleBackGrad},
new int[]{90}, true);
break;
case SWT.Deactivate:
folder.setSelectionForeground(titleFore);
folder.setSelectionBackground(
new Color[] {titleInactiveBack, titleInactiveBackGrad},
new int[]{90}, true);
break;
}
}
};
folder.addListener(SWT.Activate, listener);
folder.addListener(SWT.Deactivate, listener);

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

"Alex Malinovich" <demonbane@the-love-shack.net> wrote in message
news:fa4061c4da459f8963f194f014749b3d$1@www.eclipse.org...
> I'm having a problem with my CTabFolder not gaining and losing focus
> "correctly". I'm trying to emulate the Eclipse editor behavior for the
> tabs. The first problem is that accountTabs is losing focus to widgets
> which are its children. I have a table with accountTabs set as its parent,
> and it will actually take focus away from accountTabs.
>
> The other problem is that once the focus is gone, the only way to get it
> back is to click on the tab and then push Tab on my keyboard. Just
> clicking on the tabs changes the active tab, but it does NOT generate a
> focusGained event. Any help is greatly appreciated.
>
> I'm creating the CTabFolder using the following:
>
> final CTabFolder accountTabs = new CTabFolder(msgShell, SWT.TOP);
> accountTabs.setSimple(false);
> accountTabs.setBorderVisible(true);
> accountTabs.setTabHeight(accountTabs.getTabHeight() + 5);
>
> accountTabs.addFocusListener(new FocusAdapter() {
> public void focusGained(FocusEvent e) {
> accountTabs.setSelectionForeground(
> display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND));
> accountTabs.setSelectionBackground(
> new Color[]{display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND),
> display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)} , new
> int[]{90}, true);
> }
> public void focusLost(FocusEvent e) {
> accountTabs.setSelectionForeground(
> display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND));
> accountTabs.setSelectionBackground(
> new Color[]
> {display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_ GRADIENT),
> display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)} , new
> int[]{90}, true);
> }
> }
> });
>
>
Re: CTabItem not focusing as expected [message #463468 is a reply to message #463458] Mon, 07 November 2005 16:26 Go to previous message
Alex Malinovich is currently offline Alex MalinovichFriend
Messages: 5
Registered: July 2009
Junior Member
The Activate and Deactivate events where exactly what I was looking for.
Thanks!

The only problem I have now is that when I open the folder I am making
sure that the selection is on the tab that the user requested when they
first opened the window. But by using setSelection(index) I seem to be
giving the targeted tab keyboard focus. (The tab title gets underlined.)

The first time the user does anything in the window other than
clicking one of the other tabs, this now goes away and the colors stay the
way they should. But it might be confusing the first time that they see
it. I've tried using a SWT.FocusIn listener and setting event.doit =
false, but this didn't work.

On Mon, 07 Nov 2005 10:29:42 -0500, Veronika Irvine wrote:

> The focus event is only sent when the folder itself gets focus. Typically,
> you do not want the folder tabs to take focus because the action the user
> wants to take after selecting a tab is to enter information in the contents
> of the tab. Requiring a second click to get to the text field etc is
> annoying to the user.
>
> In your case, to change the colours of the tabs, try using the Activate and
> Deactivate events as shown below:
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> shell.setLayout(new FillLayout());
> Button b = new Button(shell, SWT.PUSH);
> b.setText("Button 1");
> final CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
> CTabItem item = new CTabItem(folder, SWT.NONE);
> item.setText("title for tab 1");
> b = new Button(folder, SWT.PUSH);
> b.setText("Button 2");
> item.setControl(b);
> item = new CTabItem(folder, SWT.NONE);
> item.setText("title for tab 2");
> b = new Button(folder, SWT.PUSH);
> b.setText("Button 3");
> item.setControl(b);
> b = new Button(shell, SWT.PUSH);
> b.setText("Button 4");
>
> final Color titleFore =
> display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND);
> final Color titleBack =
> display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
> final Color titleBackGrad =
> display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
> final Color titleInactiveBackGrad =
> display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_G RADIENT);
> final Color titleInactiveBack =
> display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND);
>
> Listener listener = new Listener() {
> public void handleEvent(Event e) {
> switch (e.type) {
> case SWT.Activate:
> folder.setSelectionForeground(titleFore);
> folder.setSelectionBackground(
> new Color[]{titleBack, titleBackGrad},
> new int[]{90}, true);
> break;
> case SWT.Deactivate:
> folder.setSelectionForeground(titleFore);
> folder.setSelectionBackground(
> new Color[] {titleInactiveBack, titleInactiveBackGrad},
> new int[]{90}, true);
> break;
> }
> }
> };
> folder.addListener(SWT.Activate, listener);
> folder.addListener(SWT.Deactivate, listener);
>
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
Previous Topic:How to select only one cell in a Table
Next Topic:SWT Universal Binary for Mac OS X86
Goto Forum:
  


Current Time: Thu Apr 25 02:33:12 GMT 2024

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

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

Back to the top