ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi:
I am writing a Java program that uses a TrayIcon. On XFCE the displayMessage() method shows the message but only occasionally, does anyone know why this would be?
-Jamie
the code block would be nice to see,
does it have a time limit that has to be met before message is shown?
is the pointer where it has to be in order for it to register an 'on_focus' event (I don't now what the actual event name is) if that is even how you're implementing it, or if it is to show a message for some other reason.
What is suppose to be triggering the function call to show Message?
here is the Java docs (?) on it
Code:
java.awt
Class TrayIcon
java.lang.Object
java.awt.TrayIcon
/**
* Displays a tooltip above the icon for a short period of time.
*
* @param message The message to be displayed
* @param title The title.
* @param icon The icon to use.
*/
public void notifyUser(String message, String title, TrayIcon.MessageType icon) {
_ni.displayMessage(title, message, icon);
S_lastMessage = message;
}
_ni is an instance of TrayIcon. (Used to be "NoteifyIcon" before I ported this too Java). Ther is no time limit. It's connected to the tray like this:
BufferedImage iconForTray = null;
Code:
try {
iconForTray = ImageIO.read(new File("cr.png"));// Forgot about recouces, we never got them to work in the C# ver.
} catch (IOException e1) {
JOptionPane.showMessageDialog(null, "This program has been damaged, please re-download it!",
"Oh darn!", JOptionPane.ERROR_MESSAGE);
// We assume, it's damage since they should be no reason why
// We can't read the icon otherwise.
System.err.println(e1.getMessage());
System.exit(9);
}
gram._ni = new TrayIcon(iconForTray);
gram._ni.addActionListener(gram);
SystemTray theTray = SystemTray.getSystemTray();
Last edited by jamie marchant; 04-29-2017 at 10:12 AM.
1. displayMessage() method shows the message but only occasionally.
that is a function call, yes?
Correct.
Quote:
2. notifyUser(String message, String title, TrayIcon.MessageType icon)
that is a different function call, yes?
The notifyUser() method calls the displayMessage() method. The displayMessage() method is in the official Java API.
Quote:
3. in your catch error to call to print a message,
System.err.println(e1.getMessage());
that is to print line - does that not come out on a command line and not message "box"?
That is correct. I am in pre-alpha stages at the moment so I am running my program from an IDE which has a "command line".
Quote:
I do not see anywhere in the other two code blocks you calling displayMessage.
That is correct, it is used in several locations throughout the program but never for crashes. Here is an example where it's used:
Code:
gram.notifyUser("Double-click the icon for volume control.", "Your reader is ready!", TrayIcon.MessageType.INFO);
//Application.Run(gram);
System.out.println("[DEBUG]: Last instruction ran, program should now run in the background.");
The debug statement IS printed.
Quote:
that is only when there is an error ... maybe it is not seeing that "test" error as an error all of the time?
Is it a test error yes?
If it was seeing that error all the time I would get a message and the program would quite. Notice the line:
"System.exit(9);"
It is not a 'test', Java will execute that code if it can't read the icon file of my disk.
because it is only showing sometimes. means their has to be a 'short' in your line of code connections. All of the 'wires' are not connected properly to the 'switch' analogy.
one call is connected properly so it does works
another call is not connected properly so it does not work.
That is what I'd be looking in to. Making sure all of your connections are set up properly . have it println("this is where I am being called from") for every displayMessage() that is to be called then look at your terminal out put to find which ones are not being called/working.
That's a good idea. I've already noticed the same message called from the same place will usually not show up. I'm not sure what is different in the tray when it does. It seems to be consistent when using Gnome-shell or KDE, even though those desktop environments have their own bugs with Java tray icons.
Hmm... this gives me an idea, I wonder if there is an alternative class I can use, that is less buggy.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.