|
Re: Change text in a view (Simple help needed!) [message #665272 is a reply to message #665250] |
Thu, 14 April 2011 00:36 |
Eclipse User |
|
|
|
Originally posted by: rth_morpheus.web.de
Am 13.04.2011 23:20, schrieb LHXS:
> Dear all,
>
> Just a simple one (hopefully)
>
> I have followed the tutorials at
> http://www.vogella.de/articles/EclipseRCP/article.html
>
> and I have an RCP application with a few views. First thing is, how do I
> get the button that I have created to add something into a view, for
> example, just add a new lone of text?!
>
> All help is appreciated!
>
> Many thanks
>
> Matt
If you want a Button to alter the text of a Text widget, you need to add
a SelectionListener to that Button just like this:
Text textField = new Text(...);
Button myButton = new Button(...)
myButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
textField.setText("new Text");
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
You can just ignore the widgetDefaultSelected method for this.
Regards
Robert
|
|
|
|
|
Re: Change text in a view (Simple help needed!) [message #665528 is a reply to message #665474] |
Thu, 14 April 2011 22:41 |
Eclipse User |
|
|
|
Originally posted by: rth_morpheus.web.de
Am 14.04.2011 19:42, schrieb LHXS:
> John,
>
> Many thanks
>
> Call me a dufus but....
>
>
> What are the dots in the parenthesis supposed to represent? E.G.
> "Text(...);"
>
> Many thanks!
>
> Matt
>
>
I just used the dots in order to shorten the example code. A Button or
Text widget require, depending on the used constructor, several
arguments, which I thought not to be necessary to illustrate the qay of
solving your issue.
Regards
Robert
|
|
|
Re: Change text in a view (Simple help needed!) [message #665529 is a reply to message #665481] |
Thu, 14 April 2011 22:53 |
Eclipse User |
|
|
|
Originally posted by: rth_morpheus.web.de
Am 14.04.2011 20:36, schrieb LHXS:
> Actually I think my problem is not so much that (although an answer to
> that would be great) but more importantly:
>
>
>
> How do I get a handle on the textbox that I want to send text into?
>
> Do you think you could comment your code for a noob like me?
>
> Many thanks
>
> Matt
Oh sorry, I just read your previous post first. To answer your questions:
You don't need a handler for the Text box itself. If you add a selection
listener to the button you press in order to change the displayed
content of your text box, this listener will do the work.
A commented example:
// create a new text box, the dots are just for shortening the example.
// depending on the constructor you use, you will require several
// arguments, e.g. the parent Composite, a Layout and so on
// using the auto completition of eclipse is a good way to get an
// overview of the possible constructors
Text textField = new Text(...);
// create a new button, same reason for dots as above
Button myButton = new Button(...);
// add a selection listener to the button
// this listener tells the button what to do, if you click it
myButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
// this method tells the listener what to do, if the button is pressed
// in this case, pressing the button changes the text in the previously
// created text box to "new Text"
textField.setText("new Text");
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// this method remains empty
}
});
Regards
Robert
|
|
|
Powered by
FUDForum. Page generated in 0.03572 seconds