aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem setting focus for a newly added child element in TreeViewer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem setting focus for a newly added child element in TreeViewer" Watch "Problem setting focus for a newly added child element in TreeViewer" New topic
Author

Problem setting focus for a newly added child element in TreeViewer

b gorle
Greenhorn

Joined: Mar 24, 2010
Posts: 3
Hi

My treeviewer contains both parent and child elements. When I am trying to add a new child element for a particular parent element, some how the focus is getting lost. My code goes like this

protected void setSelectionToViewer(final Collection theSelection)

{

if (theSelection != null && !theSelection.isEmpty())

{

// Try to select the items in the current content viewer of the editor.

Object[] asArray = theSelection.toArray();

if (collectionViewer != null && asArray != null

&& asArray.length > 0 && asArray[0] != null)

{

collectionViewer.getViewer().reveal(asArray[0]);

collectionViewer.getViewer().setSelection(new StructuredSelection(asArray), true);

collectionViewer.getViewer().getControl().setFocus();

//myTreeViewer.getControl().setFocus();

}

}

}

Any help is highly appreciated. Thanks in advances bgorle.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

Please Use Code Tags.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
b gorle
Greenhorn

Joined: Mar 24, 2010
Posts: 3
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
quick quiz for you:
which is easier to read, in the way you're used to seeing it

1)
class FirstProgram
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}

or
2)


or
3)
b gorle
Greenhorn

Joined: Mar 24, 2010
Posts: 3
Sorry for that!! Please check it now. Also if you are unable to understand below code please suggest what is the general procedure to set Focus for a newly added child element in a treeview. When I add an element, the focus should be on the newly added element, but for some reason i am unable to set the focus and it is lost ...



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem setting focus for a newly added child element in TreeViewer