Create Control Dynamically [message #720484] |
Tue, 30 August 2011 17:09 |
Balaji Messages: 17 Registered: August 2011 |
Junior Member |
|
|
Hi
I want to dynamically create 'n' number of control(say TextBox or Label) and want to have an action to all Controls.
Example
--------
1. Dynamically Create 10 Textbox
2. On CARRIAGE return of it perform some operation (addKeyListener)
(Edited)
My Question
-----------
How to I add action to those created controls?
Is there any Control Array(same as VB)
[Updated on: Wed, 31 August 2011 02:59] Report message to a moderator
|
|
|
Re: Create Control Dynamically [message #720728 is a reply to message #720484] |
Wed, 31 August 2011 06:52 |
Eclipse User |
|
|
|
Originally posted by:
On 2011-08-30 19:09, Balaji wrote:
> Hi I want to dynamically create 'n' number of control(say TextBox or
> Label) and want to have an action to all Controls.
1) There is no 'TextBox' in SWT, do you mean the
org.eclipse.swt.widgets.Text widget?
2) You don say what kind of "actions" you are referring to. Do you want
to register a SelectionListener or a generic Listener?
> Example
> --------
> 1. Dynamically Create 10 Textbox
>
> 2. Specific 5 TextBox has to perform some action on CARRIAGE RETURN and
> other 5 perform some action on ESCAPE key
>
> My Question
> -----------
> How to I add action to those created controls?
I don't understand the question. If you are writing a loop to generate
the control, why is there there a problem to add the listeners within
the loop?
> Is there any Control Array(same as VB)
I don't know, what a Control Array is, but you can simply create a
java.util.List<org.eclipse.swt.widgets.Control> if you really need to.
HTH & Greetings from Bremen,
- Daniel Krügler
|
|
|
|
Re: Create Control Dynamically [message #722333 is a reply to message #721889] |
Mon, 05 September 2011 12:06 |
Eclipse User |
|
|
|
Originally posted by:
On 2011-09-03 13:56, Balaji wrote:
> Hi
> Thanks.
> Here is the sample code, where I want to create a 'n' Label and want to
> perform a move operation on selected Label.
>
> Example
>
>
> Label label;
>
> Listener listener = new Listener () {
> public void handleEvent (Event event) {
> ...
> // MY HANDLER HERE
> ...
> ...
> }
> }
>
>
> for(...) { label = new Label(composite, SWT.NONE);
> label.addListener (SWT.MouseDown, listener);
> }
>
>
>
> Please correct me if anything is wrong.
>
> My Doubt
> --------
> In the above case, in the handler how do I know on which Label its
> operating?
The event handler function provides an Event object. Look at the member
"widget" to get access to the widget that had caused the event to fire.
HTH & Greetings from Bremen,
- Daniel Krügler
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02304 seconds