Java TrayIcon message close button - java

The real question here might be if there's a better way to display desktop messages in Java. However...
I'm using the Java trayicon to display messages to a desktop user. Because they want to keep certain messages up until the user clicks on them, in order to use the 'displayMessage' feature, I have to keep displaying them until the user clicks on them and I get an action command. However, if the user clicks on the little close button, I don't get an action command.
I'm developing this on linux, but the users are on windows, which complicates the testing. Also, obviously this isn't what the trayicon functionality was designed for, so if there's a better way to do this, let me know.
Thanks in advance.

What about just using a dialog window, e.g. java.swing.JOptionPane.showConfirmDialog(...)?
Here's an article about it: http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html

Related

JOptionPane.showConfirmDialog blocks the background windows

JOptionPane.showConfirmDialog popup (Y/N dialogues) blocks accessing other windows of the same application. (needless to mention I know it is the nature of this dialogue to bock other windows, however I dont want it for this app).
In an application I open several jframes in each an image is loaded. Then at the end I ask user whether he/she wants the images to be saved or not. but the user has no access to go back and look at those windows as the JOptionPane.showConfirmDialog does not allow it. How can I set up JOptionPane.showConfirmDialog so that I still have access to the underneath windows?
The JOptionPane dialogs are "modal" which means they intentionally block other windows, forcing the user to make a decision before continuing.
Try JDialog instead and setModal() to false.
How can I set up JOptionPane.showConfirmDialog so that I still have access to the underneath windows?
Read the JOptionPane API. It shows you how to manually create and display the option pane. Since you have direct access to the dialog used and you can make it non-modal.

System tray with Java

I've set my program to appear in the system tray by doing what Oracle told to do. My first question is about the icon. I have a lot of programs in the system tray and mine is hidden. Can I make it to show in the bar without needing to click the arrow in the tray?
I also figured out that I can display a message by calling trayIcon.displayMessage(title, content, icon). I wonder if I can change the outlook of the balloon in the way Skype has done it.
Or do I need to use someting else do display a message? It should appear always in the front of all the applications and it shouldn't hinder other applications. For example if the user is playing a game, the information dialog shouldn't steal the focus from mouse and keyboard.
No you cant change the style of the baloon using the java systray mechanism. Skype doesnt use the java mechanism to show the systray. It is the systems task to style and display the baloon.
To show your icon, it is a windows configuration - when you click the arrow, there is a "customize" link, where you can configure which icons are displayed.
If you want to influence the style of the window, you need to implement your custom Frame that feels like and is positioned like a systray info window. And you would not use the Tray classes.
Concerning your question regarding skinning. The SystemTray displayMessage balloon can not be customized in any way.

give an application focus in java

I want to partially automate some integration level tests via the use of the Robot class to send mouse/keyboard events to the the Java application I'm testing. I want the user to be able to click a button and have a number of keyboard events be automatically sent at once.
I spawn the application I want to test from inside my Robot test (using Runtime.exec) and then generate the appropriate events. Unfortunately when the user clicks a button the button has focus and receives the events instead of the events going to the child process as I would like. I would like a way to ensure that the Robot keyboard events are sent to the application I'm trying to test instead.
I've thought of fetching the child process PID and then using the FG command to bring the application I want to the foreground; but this is a Linux specific approach. I would prefer a method that works for Linux or Windows equally as well.
I don't know exactly what you are testing or how you are testing it but you should look into Sikuli - its a visual technology and there are methods that will let you either automatically click on a part of the screen you want to get focus, or use App.focus("application name"). I really recommend it. However using it will not let you use the computer to do other things while testing the program.
Hope that helps!

Java GUI How to Popup Message Windows like MSN Messenger

My Java application sometimes stays at system tray, just like MSN messenger does. I need popup a window to display some formated texts. Sometimes there is more than 1 message entry. I need to display them all.
I am new to jave Swing/GUI.
Anyone has idea or experience on this?
I haven't had the opportunity to work with the Java system tray functionality yet, but you might be interested in reading this overview.
One particular section that appears to describe what you want is this:
Finally, if you wish to casually notify the user of a change in application status using a tooltip from the tray icon, use the displayMessage() method. This method displays a popup message near the tray icon, which will disappear after a time or if the user clicks on it. Clicking on the message may trigger an ActionEvent, depending on the platform.
That sounds like it describes what you want to do, but I'm not sure if there are any limitations on it. With that, the SystemTray and TrayIcon classes might be of interest as well, although I'm guessing that you've read them already.
The system tray functionality in Java 6 allows you to do what you want. Namely have an icon there, which your application can then react to. The functionality to show a message bubble is available.
I have found that the display of multiple individual messages varies a lot between platforms, so I would group them together in a time interval and show them together instead of individual bubbles.
Have a look at http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/systemtray/

Recommended technology choice for desktop application

I am creating an application that is essentially a financial alerts site. I am a basic level Java programmer, and I have created some of the logic for alerts in Java.
I want to be able to have pop-ups appear on the desktop whenever something "interesting" happens (interesting depends on %change, liquidity and a few other simple factors).
What is the best combo of technology to implement something like this?
I would use the java.awt.SystemTray in Java SE 6. It's cross-platform and pretty easy to use.
Although some people hate the balloon notifications in Windows, they're the least obtrusive popups, since they can be ignored by the user or easily dismissed. Most importantly, they can't be missed by the user who has been away from the computer, because balloons (at least in Windows XP/Vista) use system idle timers to determine when's the right time to disappear.
Some prefer more traditional toast notifications, similar to those shown by Outlook - they show up and slowly fade out, giving the user some time to interact with them if needed.
I had the same problem and finally solved it using an undecorated, alwaysOnTop window.
And thanks to this blog entry I found the TimingFramework, and now it even is translucent, fades in and out, goes 100% opaque on mouse over etc. In conjunction with the SystemTray and TrayIcon the behavior is nearly as that of Outlook.
Oh, I have to note, that other than the second link, I do the fading out with
AWTUtilities.setWindowOpacity(window, op);
You could write a java program that resides in the system tray, but I am not sure if there are cross platform compatible ways to do this. maybe you have to use a platform specific library for Win, Mac, Linux, ...
I'd just create a message window and animate it. Then add SystemTray support and voila, you're done.
In Delphi you can do that pretty quickly, but you can't easily reuse your java logic
You can just run you program in "silent" mode, without creating any windows by default, maybe just a little icon in the taskbar which when double-clicked will open a settings window. The program will be running in the background and creating windows with the set focus whenever an event happens.
But in my opinion, a slide window or at least a balloon tooltip is a better idea.

Categories