Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Get which TreeItem has focus in a Tree ?
Get which TreeItem has focus in a Tree ? [message #491549] Wed, 14 October 2009 23:45 Go to next message
Gary Miguel is currently offline Gary MiguelFriend
Messages: 15
Registered: October 2009
Junior Member
Hi,
is there any way to figure out which individual TreeItem has focus?
If I call display.getFocusControl(), I get the Tree back, even though the dotted outline is on a leaf.

Thanks,
Gary
Re: Get which TreeItem has focus in a Tree ? [message #491590 is a reply to message #491549] Thu, 15 October 2009 07:52 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
Gary Miguel wrote:
> Hi,
> is there any way to figure out which individual TreeItem has focus?
> If I call display.getFocusControl(), I get the Tree back, even though
> the dotted outline is on a leaf.

TreeItems are Widgets and no Controls, therefore they don't have a focus
concept.

HTH & Greetings from Bremen,

Daniel Krügler
Re: Get which TreeItem has focus in a Tree ? [message #491721 is a reply to message #491590] Thu, 15 October 2009 14:59 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
A Table/TreeItem can show a focus rectangle on some platforms, but there's
no API for getting the item that has this (such API would be similar to
Table/Tree.getSelection()).

There is a sneaky way to get it on win32 and motif though, as shown in the
snippet below. This snippet should work on gtk as well but doesn't due to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=292413 . OS X does not have
the concept of a focused Table/Tree item.

public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.setLayout(new FillLayout());
final Tree tree = new Tree(shell, SWT.MULTI);
for (int i = 0; i < 9; i++) {
new TreeItem(tree, SWT.NONE).setText("item " + i);
}
tree.addListener(SWT.PaintItem, new Listener() {
public void handleEvent(Event event) {
if ((event.detail & SWT.FOCUSED) != 0) {
System.out.println("item has focus: " +
((TreeItem)event.item).getText());
}
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant


"Daniel Kr
Re: Get which TreeItem has focus in a Tree ? [message #491751 is a reply to message #491721] Thu, 15 October 2009 16:31 Go to previous messageGo to next message
Gary Miguel is currently offline Gary MiguelFriend
Messages: 15
Registered: October 2009
Junior Member
Thank you very much. I am writing for win32, though ideally we'd want something that works on 64-bit Windows Vista and Windows 7. Any idea if this will break?

With this trick you showed me, I should be able to make a wrapper class for Tree that keeps track of which TreeItem has focus.
Re: Get which TreeItem has focus in a Tree ? [message #491814 is a reply to message #491549] Thu, 15 October 2009 23:30 Go to previous messageGo to next message
Gary Miguel is currently offline Gary MiguelFriend
Messages: 15
Registered: October 2009
Junior Member
Hmm, it seems that on Windows XP, there's no focused TreeItem until you use the keyboard to navigate through the Tree. If I open my app and just use the mouse to click, shift-click, control-click, etc, there's no dotted line, and the listener never gets called.

I suppose I can see why it's not a supported SWT feature...
Re: Get which TreeItem has focus in a Tree ? [message #491914 is a reply to message #491814] Fri, 16 October 2009 14:09 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Yes, that's native focus rectangle behaviour. Encouraging apps to depend on
it in general, especially across platforms, probably wouldn't be doing them
any favours.

The snippet in my other reply should work equally well on 64-bit Windows and
Windows 7, assuming that native Tables and Trees in Windows 7 show focus
rectangles.

Grant


"Gary Miguel" <gmiguel@informatica.com> wrote in message
news:hb8bba$hc3$1@build.eclipse.org...
> Hmm, it seems that on Windows XP, there's no focused TreeItem until you
use the keyboard to navigate through the Tree. If I open my app and just use
the mouse to click, shift-click, control-click, etc, there's no dotted line,
and the listener never gets called.
>
> I suppose I can see why it's not a supported SWT feature...
Previous Topic:SWT controls and larger font
Next Topic:Problem with SWT Browser and IE7
Goto Forum:
  


Current Time: Sun Sep 15 16:43:11 GMT 2019

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

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

Back to the top