[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: SWT Text problem in Tree in Red Hat Linux
|
Hi Grant,
I took a further look at the code and the text box is actually in a tree. So
may be it occurs only when it is inside a tree. Once again, it only occurs
inside Linux.
I am running on WSAD v5 GA and it is not a standalone program. But I think
you can just create a TreeViewer
and add the following code.
Here is the code I have:
// beginning
// Assume I have a TreeViewer called treeViewer
Tree tree = treeViewer.getTree();
TreeEditor treeEditor = new TreeEditor(tree);
// Use a Composite containing a Label and a Text. This allows us to edit
just
// the value, while still showing the variable name.
composite = new Composite(tree, SWT.NONE);
composite.setBackground(tree.getBackground());
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
editorLabel = new Label(composite, SWT.LEFT);
editorLabel.setLayoutData(new GridData(GridData.FILL_VERTICAL));
editorText = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.LEFT );
editorText.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
// get the value
String valueString = "someValue";
TreeItem[] selectedItems = tree.getSelection();
treeEditor.horizontalAlignment = SWT.LEFT;
treeEditor.grabHorizontal = true;
treeEditor.setEditor(composite, selectedItems[0]);
//get the name
String varName = "someVariableName";
editorLabel.setText(varName + "=");
editorText.setText(valueString);
editorText.selectAll();
composite.layout(true);
composite.setVisible(true);
editorText.setFocus();
// CR means commit the change, ESC means abort changing the value
editorText.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent event) {
// ... some actions
}
});
// If the focus is lost, then act as if user hit CR and commit change
editorText.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent fe) {
// .. some actions
}
});
// end
Thanks,
Grace
Grant Gayed wrote:
> Grace,
>
> I don't see this behaviour in either of the linux/swt implementations, and
> haven't heard of this before.
>
> Are you using an Eclipse build from the current stream or Eclipse 2.0.2?
> And do you have a stand-alone test case that shows the problem? I tried
> your snippet and it behaved normally, but with all of the elipsed-out
> sections I'm not really running the same thing that you are.
>
> Grant
>
> Grace wrote:
>
> > Hi,
>
> > I wonder if you have seen this problem when running on Red Hat Linux
> > with Gnome.
>
> > I am trying to add a text inside a composite. It works fine on
> > Windows where the text box can be edited.
> > But on Linux, when the text box is chosen, the values becomes a thick
> > black dash, like "---" and the newly edited text
> > cannot be shown. Do you have any clues?
>
> > The code is something like this:
>
> > org.eclipse.swt.widgets.Composite composite = .....; // set the
> > composite
> > org.eclipse.swt.widgets.Text editorText = new Text(composite,
> > SWT.BORDER | SWT.SINGLE | SWT.LEFT);
> > editorText.setLayoutData( new GridData(GridData.FILL_HORIZONTAL |
> > GridData.FILL_VERTICAL));
>
> > // get the value
> > String valueString = "someValue";
> > .......
>
> > editorText.setText(valueString);
> > editorText.selectAll();
>
> > composite.layout(true);
> > composite.setVisible(true);
> > editorText.setFocus();
>
> > // events of changing the value
> > editorText.addKeyListener(new KeyAdapter() {
> > public void keyReleased(KeyEvent event) {
> > ......
> > }
> > });
>
> > // If the focus is lost, then do certain things
> > editorText.addFocusListener(new FocusAdapter() {
> > public void focusLost(FocusEvent fe) {
> > .......
> > }
> > });
> > ........