Detecting Combo Events [message #447883] |
Mon, 20 December 2004 20:00  |
Eclipse User |
|
|
|
How do you get the text that was on an SWT Combo box when an event was
triggered? I can trigger the event but I can't for the life of me figure
out how to capture the information I see contained in the event.
Any suggestions?
I have a combo box within a table that is itself within a CTabFolder. I
want to pull out the event but nothing seems to produce the text.
Thank you,
Ty
|
|
|
|
|
|
Re: Detecting Combo Events [Code Included] [message #447913 is a reply to message #447911] |
Tue, 21 December 2004 15:53  |
Eclipse User |
|
|
|
Steve,
Thank you kindly for replying. Your example indeed works. I guess my
problem is slightly different. In your example you're using an anonymous
handler. I was using a separate class as the handler.
In my separate-class handler, I have the following code:
else if( event == tabs.claimsDrop )
{
String text = tabs.claimsDrop.getText();
System.out.println( "text=" + text );
}
'tabs' is a reference to a Shell that displays a table.
'claimsDrop' is a Combo box that appears in a Table that itself lives
in a TabFolder on the 'tabs' screen. Although I can see the references
above ('tabs' and 'claimsDrop' have scope that is visible), I'm not,
apparently, referencing them correctly. Although the Combo box triggers
the event correctly, the reference of the event does not match the event
I'm referencing above. Perhaps I'm asking too much, but do you have any
insights why it does not recognise my handler reference?
thank you,
Ty
Steve Northover wrote:
> WORKSFORME
> Here is my output when I use the arrow keys and select with the mouse:
> your selection is Item 1
> text=Item 1
> text2=Item 1
> your selection is Item 2
> text=Item 2
> text2=Item 2
> your selection is Item 3
> text=Item 3
> text2=Item 3
> your selection is Item 4
> text=Item 4
> text2=Item 4
> Here is the test code:
> import org.eclipse.swt.*;
> import org.eclipse.swt.events.*;
> import org.eclipse.swt.widgets.*;
> public class EclipseCorner {
> public static void main(String[] args) {
> final Display display = new Display();
> final Shell shell = new Shell(display);
> final Combo claimsDrop = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
> for (int i=0; i<32; i++) claimsDrop.add ("Item " + i);
> claimsDrop.select(0);
> claimsDrop.addModifyListener(new ModifyListener() {
> public void modifyText(ModifyEvent e) {
> int i = claimsDrop.getSelectionIndex();
> String text = claimsDrop.getItem(i);
> System.out.println("your selection is " + text);
> }
> });
> claimsDrop.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent se) {
> String text = claimsDrop.getText();
> System.out.println("text=" + text);
> int i = claimsDrop.getSelectionIndex();
> String text2 = claimsDrop.getItem(i);
> System.out.println("text2=" + text2);
> }
> });
> claimsDrop.pack ();
> shell.pack();
> shell.open();
> while (!shell.isDisposed()) {
> if (display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
> "Tyrone Hed" <tyronehed@earthlink.net> wrote in message
> news:cq9rpb$c1h$1@www.eclipse.org...
>> Here's my problem. No matter what I do, I cannot get access to the text
>> or index on the Combo box. Although, when I debug, the event shows it
>> carries the text that occurred with the event, I cannot find out how to
>> pull out this information. The event always pulls back "" (blank) text.
>>
>> Does anyone know how to correctly interpret events from a Combo box? I
>> have two examples below. I have gotten both to trigger events but I have
>> never been able to figure out how to grab that event information.
>>
>> Thank you,
>> Ty
>>
>>
>> Combo claimsDrop = new Combo( table, SWT.DROP_DOWN | SWT.READ_ONLY |
>> SWT.SIMPLE );
>> claimsDrop.addModifyListener(
>> new ModifyListener()
>> {
>> public void modifyText(ModifyEvent e)
>> {
>> int i = claimsDrop.getSelectionIndex();
>> String text = claimsDrop.getItem( i );
>> System.out.println("your selection is " + text );
>> }
>> }
>> );
>>
>> claimsDrop.addSelectionListener(
>> new SelectionAdapter()
>> {
>> public void widgetSelected( SelectionEvent se )
>> {
>> String text = claimsDrop.getText();
>> System.out.println( "text=" + text );
>> int i = claimsDrop.getSelectionIndex();
>> String text2 = claimsDrop.getItem( i );
>> System.out.println( "text2=" + text2 );
>> }
>> }
>> );
>>
>>
|
|
|
Powered by
FUDForum. Page generated in 0.24526 seconds