Home » Eclipse Projects » Rich Client Platform (RCP) » Tray icon for application window
Tray icon for application window [message #460690] |
Thu, 28 December 2006 07:02  |
Eclipse User |
|
|
|
Originally posted by: partyhut.internode.on.net
Hi all,
I checked the tray icon snippet for SWT application and try to add a
display of tray icon after my application window is closed... I put my
code in configureShell because the example used shell to create the tray
item. However it doesn't work...there is no error message. The
application ran and after I clicked on the close button on my app
window, the system tray didn't show up...I think the way I add listener
to the shell is wrong... Can anybody point me to the right direction?
Also I would like to know how to show the app window after a user double
click on the tray icon. Thank you in advance.
protected void configureShell(Shell newShell)
{
super.configureShell(newShell);
newShell.setText(Messages.getString("Example"));
newShell.addListener(SWT.Close, new Listener() {
public void handleEvent (Event event) {
final Tray tray = Display.getCurrent().getSystemTray ();
if (tray == null) {
System.out.println ("The system tray is not available");
} else {
final TrayItem item = new TrayItem (tray, SWT.NONE);
item.setToolTipText("My application");
item.addListener (SWT.Show, new Listener () {
public void handleEvent (Event event) {
System.out.println("show");
}
});
|
|
| | |
Re: Tray icon for application window [message #460693 is a reply to message #460692] |
Thu, 28 December 2006 07:57   |
Eclipse User |
|
|
|
Originally posted by: partyhut.internode.on.net
Hi Tom,
Thank you for your prompt response. You mean I should do something like
while (true) {}? Is there a standard way to make a System Tray Icon work
properly? I also want to bring back the app window after user click on
it... If you have come across this issue before, please tell me how to
bring back the app window. :) THX
Tom Schindl wrote:
> Hi,
>
> I think you need to control the event loop your own else the application
> -window leaves the loop and java programm is ending ;-)
>
> Tom
>
> HS schrieb:
>> Solved the first problem by changing the addListener to addShellListener
>> :) Now, when I close the application window, the tray item flashed and
>> disappeared...How can I make it stay alive in the system tray and bring
>> back the app window after double click?
>>
>> Cheers!
>>
>>
>> HS wrote:
>>> Hi all,
>>>
>>> I checked the tray icon snippet for SWT application and try to add a
>>> display of tray icon after my application window is closed... I put my
>>> code in configureShell because the example used shell to create the
>>> tray item. However it doesn't work...there is no error message. The
>>> application ran and after I clicked on the close button on my app
>>> window, the system tray didn't show up...I think the way I add
>>> listener to the shell is wrong... Can anybody point me to the right
>>> direction? Also I would like to know how to show the app window after
>>> a user double click on the tray icon. Thank you in advance.
>>>
>>> protected void configureShell(Shell newShell)
>>> {
>>> super.configureShell(newShell);
>>> newShell.setText(Messages.getString("Example"));
>>> newShell.addListener(SWT.Close, new Listener() {
>>> public void handleEvent (Event event) {
>>> final Tray tray = Display.getCurrent().getSystemTray ();
>>> if (tray == null) {
>>> System.out.println ("The system tray is not available");
>>> } else {
>>> final TrayItem item = new TrayItem (tray, SWT.NONE);
>>> item.setToolTipText("My application");
>>> item.addListener (SWT.Show, new Listener () {
>>> public void handleEvent (Event event) {
>>> System.out.println("show");
>>> }
>>> });
|
|
|
Re: Tray icon for application window [message #460694 is a reply to message #460693] |
Thu, 28 December 2006 08:03   |
Eclipse User |
|
|
|
Originally posted by: partyhut.internode.on.net
This might sounds stupid but can do something like
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
to a tray item and how?
HS wrote:
> Hi Tom,
>
> Thank you for your prompt response. You mean I should do something like
> while (true) {}? Is there a standard way to make a System Tray Icon work
> properly? I also want to bring back the app window after user click on
> it... If you have come across this issue before, please tell me how to
> bring back the app window. :) THX
>
>
>
>
> Tom Schindl wrote:
>> Hi,
>>
>> I think you need to control the event loop your own else the application
>> -window leaves the loop and java programm is ending ;-)
>>
>> Tom
>>
>> HS schrieb:
>>> Solved the first problem by changing the addListener to addShellListener
>>> :) Now, when I close the application window, the tray item flashed and
>>> disappeared...How can I make it stay alive in the system tray and bring
>>> back the app window after double click?
>>>
>>> Cheers!
>>>
>>>
>>> HS wrote:
>>>> Hi all,
>>>>
>>>> I checked the tray icon snippet for SWT application and try to add a
>>>> display of tray icon after my application window is closed... I put my
>>>> code in configureShell because the example used shell to create the
>>>> tray item. However it doesn't work...there is no error message. The
>>>> application ran and after I clicked on the close button on my app
>>>> window, the system tray didn't show up...I think the way I add
>>>> listener to the shell is wrong... Can anybody point me to the right
>>>> direction? Also I would like to know how to show the app window after
>>>> a user double click on the tray icon. Thank you in advance.
>>>>
>>>> protected void configureShell(Shell newShell)
>>>> {
>>>> super.configureShell(newShell);
>>>> newShell.setText(Messages.getString("Example"));
>>>> newShell.addListener(SWT.Close, new Listener() {
>>>> public void handleEvent (Event event) {
>>>> final Tray tray = Display.getCurrent().getSystemTray ();
>>>> if (tray == null) {
>>>> System.out.println ("The system tray is not available");
>>>> } else {
>>>> final TrayItem item = new TrayItem (tray, SWT.NONE);
>>>> item.setToolTipText("My application");
>>>> item.addListener (SWT.Show, new Listener () {
>>>> public void handleEvent (Event event) {
>>>> System.out.println("show");
>>>> }
>>>> });
|
|
|
Re: Tray icon for application window [message #460695 is a reply to message #460693] |
Thu, 28 December 2006 08:05   |
Eclipse User |
|
|
|
Hi,
yes that's what I mean you need to make the event loop handling yourself
else your application simply ends.
I've never worked with it but I think you should veto to close and
simply hide the shell and then unhide it when one clicks the tray icon.
Doing it this way you don't have to catch the event loop your own ;-)
Tom
HS schrieb:
> Hi Tom,
>
> Thank you for your prompt response. You mean I should do something like
> while (true) {}? Is there a standard way to make a System Tray Icon work
> properly? I also want to bring back the app window after user click on
> it... If you have come across this issue before, please tell me how to
> bring back the app window. :) THX
>
>
>
>
> Tom Schindl wrote:
>> Hi,
>>
>> I think you need to control the event loop your own else the application
>> -window leaves the loop and java programm is ending ;-)
>>
>> Tom
>>
>> HS schrieb:
>>> Solved the first problem by changing the addListener to addShellListener
>>> :) Now, when I close the application window, the tray item flashed and
>>> disappeared...How can I make it stay alive in the system tray and bring
>>> back the app window after double click?
>>>
>>> Cheers!
>>>
>>>
>>> HS wrote:
>>>> Hi all,
>>>>
>>>> I checked the tray icon snippet for SWT application and try to add a
>>>> display of tray icon after my application window is closed... I put my
>>>> code in configureShell because the example used shell to create the
>>>> tray item. However it doesn't work...there is no error message. The
>>>> application ran and after I clicked on the close button on my app
>>>> window, the system tray didn't show up...I think the way I add
>>>> listener to the shell is wrong... Can anybody point me to the right
>>>> direction? Also I would like to know how to show the app window after
>>>> a user double click on the tray icon. Thank you in advance.
>>>>
>>>> protected void configureShell(Shell newShell)
>>>> {
>>>> super.configureShell(newShell);
>>>> newShell.setText(Messages.getString("Example"));
>>>> newShell.addListener(SWT.Close, new Listener() {
>>>> public void handleEvent (Event event) {
>>>> final Tray tray = Display.getCurrent().getSystemTray ();
>>>> if (tray == null) {
>>>> System.out.println ("The system tray is not available");
>>>> } else {
>>>> final TrayItem item = new TrayItem (tray, SWT.NONE);
>>>> item.setToolTipText("My application");
>>>> item.addListener (SWT.Show, new Listener () {
>>>> public void handleEvent (Event event) {
>>>> System.out.println("show");
>>>> }
>>>> });
|
|
|
Re: Tray icon for application window [message #460696 is a reply to message #460694] |
Thu, 28 December 2006 08:10   |
Eclipse User |
|
|
|
Originally posted by: partyhut.internode.on.net
LOL, I have got it working. Thank you for your hint Tom!
Now, How can I bring the app window back...
HS wrote:
> This might sounds stupid but can do something like
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> to a tray item and how?
>
>
> HS wrote:
>> Hi Tom,
>>
>> Thank you for your prompt response. You mean I should do something
>> like while (true) {}? Is there a standard way to make a System Tray
>> Icon work properly? I also want to bring back the app window after
>> user click on it... If you have come across this issue before, please
>> tell me how to bring back the app window. :) THX
>>
>>
>>
>>
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> I think you need to control the event loop your own else the application
>>> -window leaves the loop and java programm is ending ;-)
>>>
>>> Tom
>>>
>>> HS schrieb:
>>>> Solved the first problem by changing the addListener to
>>>> addShellListener
>>>> :) Now, when I close the application window, the tray item flashed and
>>>> disappeared...How can I make it stay alive in the system tray and bring
>>>> back the app window after double click?
>>>>
>>>> Cheers!
>>>>
>>>>
>>>> HS wrote:
>>>>> Hi all,
>>>>>
>>>>> I checked the tray icon snippet for SWT application and try to add a
>>>>> display of tray icon after my application window is closed... I put my
>>>>> code in configureShell because the example used shell to create the
>>>>> tray item. However it doesn't work...there is no error message. The
>>>>> application ran and after I clicked on the close button on my app
>>>>> window, the system tray didn't show up...I think the way I add
>>>>> listener to the shell is wrong... Can anybody point me to the right
>>>>> direction? Also I would like to know how to show the app window after
>>>>> a user double click on the tray icon. Thank you in advance.
>>>>>
>>>>> protected void configureShell(Shell newShell)
>>>>> {
>>>>> super.configureShell(newShell);
>>>>> newShell.setText(Messages.getString("Example"));
>>>>> newShell.addListener(SWT.Close, new Listener() {
>>>>> public void handleEvent (Event event) {
>>>>> final Tray tray = Display.getCurrent().getSystemTray ();
>>>>> if (tray == null) {
>>>>> System.out.println ("The system tray is not available");
>>>>> } else {
>>>>> final TrayItem item = new TrayItem (tray, SWT.NONE);
>>>>> item.setToolTipText("My application");
>>>>> item.addListener (SWT.Show, new Listener () {
>>>>> public void handleEvent (Event event) {
>>>>> System.out.println("show");
>>>>> }
>>>>> });
|
|
| |
Re: Tray icon for application window [message #460698 is a reply to message #460695] |
Thu, 28 December 2006 08:39   |
Eclipse User |
|
|
|
Originally posted by: partyhut.internode.on.net
erm... I sort of understand what you mean, but how can I override the
shell.dispose() to hide the application window...
Tom Schindl wrote:
> Hi,
>
> yes that's what I mean you need to make the event loop handling yourself
> else your application simply ends.
>
> I've never worked with it but I think you should veto to close and
> simply hide the shell and then unhide it when one clicks the tray icon.
> Doing it this way you don't have to catch the event loop your own ;-)
>
> Tom
>
> HS schrieb:
>> Hi Tom,
>>
>> Thank you for your prompt response. You mean I should do something like
>> while (true) {}? Is there a standard way to make a System Tray Icon work
>> properly? I also want to bring back the app window after user click on
>> it... If you have come across this issue before, please tell me how to
>> bring back the app window. :) THX
>>
>>
>>
>>
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> I think you need to control the event loop your own else the application
>>> -window leaves the loop and java programm is ending ;-)
>>>
>>> Tom
>>>
>>> HS schrieb:
>>>> Solved the first problem by changing the addListener to addShellListener
>>>> :) Now, when I close the application window, the tray item flashed and
>>>> disappeared...How can I make it stay alive in the system tray and bring
>>>> back the app window after double click?
>>>>
>>>> Cheers!
>>>>
>>>>
>>>> HS wrote:
>>>>> Hi all,
>>>>>
>>>>> I checked the tray icon snippet for SWT application and try to add a
>>>>> display of tray icon after my application window is closed... I put my
>>>>> code in configureShell because the example used shell to create the
>>>>> tray item. However it doesn't work...there is no error message. The
>>>>> application ran and after I clicked on the close button on my app
>>>>> window, the system tray didn't show up...I think the way I add
>>>>> listener to the shell is wrong... Can anybody point me to the right
>>>>> direction? Also I would like to know how to show the app window after
>>>>> a user double click on the tray icon. Thank you in advance.
>>>>>
>>>>> protected void configureShell(Shell newShell)
>>>>> {
>>>>> super.configureShell(newShell);
>>>>> newShell.setText(Messages.getString("Example"));
>>>>> newShell.addListener(SWT.Close, new Listener() {
>>>>> public void handleEvent (Event event) {
>>>>> final Tray tray = Display.getCurrent().getSystemTray ();
>>>>> if (tray == null) {
>>>>> System.out.println ("The system tray is not available");
>>>>> } else {
>>>>> final TrayItem item = new TrayItem (tray, SWT.NONE);
>>>>> item.setToolTipText("My application");
>>>>> item.addListener (SWT.Show, new Listener () {
>>>>> public void handleEvent (Event event) {
>>>>> System.out.println("show");
>>>>> }
>>>>> });
|
|
|
Re: Tray icon for application window [message #460699 is a reply to message #460698] |
Thu, 28 December 2006 09:08   |
Eclipse User |
|
|
|
Hi,
1. If you are running an RCP:
http://help.eclipse.org/help31/nftopic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/ui/application/WorkbenchWi ndowAdvisor.html#preWindowShellClose()
2. If you have an SWT-Standalone application:
shell.addShellListener(new ShellAdapater() {
public void shellClosed(ShellEvent e) {
e.doit = false;
}
} );
3. ApplicationWindow:
Simply overload handleShellClose()
Tom
HS schrieb:
> erm... I sort of understand what you mean, but how can I override the
> shell.dispose() to hide the application window...
>
> Tom Schindl wrote:
>> Hi,
>>
>> yes that's what I mean you need to make the event loop handling yourself
>> else your application simply ends.
>>
>> I've never worked with it but I think you should veto to close and
>> simply hide the shell and then unhide it when one clicks the tray icon.
>> Doing it this way you don't have to catch the event loop your own ;-)
>>
>> Tom
>>
>> HS schrieb:
>>> Hi Tom,
>>>
>>> Thank you for your prompt response. You mean I should do something like
>>> while (true) {}? Is there a standard way to make a System Tray Icon work
>>> properly? I also want to bring back the app window after user click on
>>> it... If you have come across this issue before, please tell me how to
>>> bring back the app window. :) THX
>>>
>>>
>>>
>>>
>>> Tom Schindl wrote:
>>>> Hi,
>>>>
>>>> I think you need to control the event loop your own else the
>>>> application
>>>> -window leaves the loop and java programm is ending ;-)
>>>>
>>>> Tom
>>>>
>>>> HS schrieb:
>>>>> Solved the first problem by changing the addListener to
>>>>> addShellListener
>>>>> :) Now, when I close the application window, the tray item flashed and
>>>>> disappeared...How can I make it stay alive in the system tray and
>>>>> bring
>>>>> back the app window after double click?
>>>>>
>>>>> Cheers!
>>>>>
>>>>>
>>>>> HS wrote:
>>>>>> Hi all,
>>>>>>
>>>>>> I checked the tray icon snippet for SWT application and try to add a
>>>>>> display of tray icon after my application window is closed... I
>>>>>> put my
>>>>>> code in configureShell because the example used shell to create the
>>>>>> tray item. However it doesn't work...there is no error message. The
>>>>>> application ran and after I clicked on the close button on my app
>>>>>> window, the system tray didn't show up...I think the way I add
>>>>>> listener to the shell is wrong... Can anybody point me to the right
>>>>>> direction? Also I would like to know how to show the app window after
>>>>>> a user double click on the tray icon. Thank you in advance.
>>>>>>
>>>>>> protected void configureShell(Shell newShell)
>>>>>> {
>>>>>> super.configureShell(newShell);
>>>>>> newShell.setText(Messages.getString("Example"));
>>>>>> newShell.addListener(SWT.Close, new Listener() {
>>>>>> public void handleEvent (Event event) {
>>>>>> final Tray tray = Display.getCurrent().getSystemTray ();
>>>>>> if (tray == null) {
>>>>>> System.out.println ("The system tray is not available");
>>>>>> } else {
>>>>>> final TrayItem item = new TrayItem (tray, SWT.NONE);
>>>>>> item.setToolTipText("My application");
>>>>>> item.addListener (SWT.Show, new Listener () {
>>>>>> public void handleEvent (Event event) {
>>>>>> System.out.println("show");
>>>>>> }
>>>>>> });
|
|
|
Re: Tray icon for application window [message #460762 is a reply to message #460699] |
Thu, 28 December 2006 19:51  |
Eclipse User |
|
|
|
Originally posted by: partyhut.internode.on.net
The handleShellClose() didn't work... I put some debug message in it and
they never get displayed... I found ApplicationWindow class is very hard
to control... I always have difficulty to find the correct shell or
display object to invoke my method on...
I added a listener to shell in configureShell to listen to the close
event. If the event is fired, a tray item will be created...
Then I try to stop the application window being disposed in
handleShellClose(). However it didn't work... seems like the window had
been disposed before this method was invoked...I got a null pointer
exception while double click on the tray item trying to bring the window
back.
Can anybody point me to the right direction?
Tom Schindl wrote:
> Hi,
>
> 1. If you are running an RCP:
> http://help.eclipse.org/help31/nftopic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/ui/application/WorkbenchWi ndowAdvisor.html#preWindowShellClose()
>
> 2. If you have an SWT-Standalone application:
> shell.addShellListener(new ShellAdapater() {
> public void shellClosed(ShellEvent e) {
> e.doit = false;
> }
> } );
>
> 3. ApplicationWindow:
> Simply overload handleShellClose()
>
> Tom
>
>
> HS schrieb:
>> erm... I sort of understand what you mean, but how can I override the
>> shell.dispose() to hide the application window...
>>
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> yes that's what I mean you need to make the event loop handling yourself
>>> else your application simply ends.
>>>
>>> I've never worked with it but I think you should veto to close and
>>> simply hide the shell and then unhide it when one clicks the tray icon.
>>> Doing it this way you don't have to catch the event loop your own ;-)
>>>
>>> Tom
>>>
>>> HS schrieb:
>>>> Hi Tom,
>>>>
>>>> Thank you for your prompt response. You mean I should do something like
>>>> while (true) {}? Is there a standard way to make a System Tray Icon work
>>>> properly? I also want to bring back the app window after user click on
>>>> it... If you have come across this issue before, please tell me how to
>>>> bring back the app window. :) THX
>>>>
>>>>
>>>>
>>>>
>>>> Tom Schindl wrote:
>>>>> Hi,
>>>>>
>>>>> I think you need to control the event loop your own else the
>>>>> application
>>>>> -window leaves the loop and java programm is ending ;-)
>>>>>
>>>>> Tom
>>>>>
>>>>> HS schrieb:
>>>>>> Solved the first problem by changing the addListener to
>>>>>> addShellListener
>>>>>> :) Now, when I close the application window, the tray item flashed and
>>>>>> disappeared...How can I make it stay alive in the system tray and
>>>>>> bring
>>>>>> back the app window after double click?
>>>>>>
>>>>>> Cheers!
>>>>>>
>>>>>>
>>>>>> HS wrote:
>>>>>>> Hi all,
>>>>>>>
>>>>>>> I checked the tray icon snippet for SWT application and try to add a
>>>>>>> display of tray icon after my application window is closed... I
>>>>>>> put my
>>>>>>> code in configureShell because the example used shell to create the
>>>>>>> tray item. However it doesn't work...there is no error message. The
>>>>>>> application ran and after I clicked on the close button on my app
>>>>>>> window, the system tray didn't show up...I think the way I add
>>>>>>> listener to the shell is wrong... Can anybody point me to the right
>>>>>>> direction? Also I would like to know how to show the app window after
>>>>>>> a user double click on the tray icon. Thank you in advance.
>>>>>>>
>>>>>>> protected void configureShell(Shell newShell)
>>>>>>> {
>>>>>>> super.configureShell(newShell);
>>>>>>> newShell.setText(Messages.getString("Example"));
>>>>>>> newShell.addListener(SWT.Close, new Listener() {
>>>>>>> public void handleEvent (Event event) {
>>>>>>> final Tray tray = Display.getCurrent().getSystemTray ();
>>>>>>> if (tray == null) {
>>>>>>> System.out.println ("The system tray is not available");
>>>>>>> } else {
>>>>>>> final TrayItem item = new TrayItem (tray, SWT.NONE);
>>>>>>> item.setToolTipText("My application");
>>>>>>> item.addListener (SWT.Show, new Listener () {
>>>>>>> public void handleEvent (Event event) {
>>>>>>> System.out.println("show");
>>>>>>> }
>>>>>>> });
|
|
|
Goto Forum:
Current Time: Sun Mar 23 20:42:20 EDT 2025
Powered by FUDForum. Page generated in 0.04955 seconds
|