LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2017, 03:39 PM   #1
jamie marchant
Member
 
Registered: Nov 2012
Distribution: Fedora 64-bit
Posts: 86

Rep: Reputation: Disabled
Java Tray Icon messages SOMETIMES don't show up.


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
 
Old 04-29-2017, 08:19 AM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Hi Jamie,

Can you confirm that the *exact same message* is shown only intermittently?

If that is not the case, then it might be that the content of the message (control characters, message length etc) is the determining factor.
 
Old 04-29-2017, 08:34 AM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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
https://docs.oracle.com/javase/7/doc.../TrayIcon.html

Last edited by BW-userx; 04-29-2017 at 08:38 AM.
 
Old 04-29-2017, 10:06 AM   #4
jamie marchant
Member
 
Registered: Nov 2012
Distribution: Fedora 64-bit
Posts: 86

Original Poster
Rep: Reputation: Disabled
I am using this method in many parts of my code:

Code:
/**
* 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.
 
Old 04-29-2017, 10:35 AM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
1. displayMessage() method shows the message but only occasionally.
that is a function call, yes?

2. notifyUser(String message, String title, TrayIcon.MessageType icon)
that is a different function call, yes?

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"?

I do not see anywhere in the other two code blocks you calling displayMessage(e1.getMessage());

something like that maybe?

in this one

JOptionPane.showMessageDialog(null, "This program has been damaged, please re-download it!",
"Oh darn!", JOptionPane.ERROR_MESSAGE);

that is only when their is an error ... maybe it is not seeing that "test" error as an error all of the time?

it is a test error yes?

Last edited by BW-userx; 04-29-2017 at 10:38 AM.
 
Old 04-29-2017, 10:55 AM   #6
jamie marchant
Member
 
Registered: Nov 2012
Distribution: Fedora 64-bit
Posts: 86

Original Poster
Rep: Reputation: Disabled
Quote:
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.
 
Old 04-29-2017, 11:13 AM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
OK I'm missing something here.
Quote:
I am using this method in many parts of my code:

public void notifyUser(String message, String title, TrayIcon.MessageType icon) {
_ni.displayMessage(title, message, icon);
S_lastMessage = message;
}
what conditions need to be met before the message shows? just an arrow over?

maybe a look over on this
System Tray Icon Example
may help

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.

Last edited by BW-userx; 04-29-2017 at 11:34 AM.
 
Old 04-29-2017, 11:38 AM   #8
jamie marchant
Member
 
Registered: Nov 2012
Distribution: Fedora 64-bit
Posts: 86

Original Poster
Rep: Reputation: Disabled
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.

I have asked about this here:
https://stackoverflow.com/questions/...a-awt-trayicon

Ok, I've found out that the message only shows up when the tray is visible. So the question is how do I force the tray to show?

Last edited by jamie marchant; 04-30-2017 at 05:31 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to remove "Show Desktop" icon from tray (Slacko 5.4 PAE) donedara Puppy 0 02-14-2013 05:45 AM
[C/C++] Show notification "balloon" on tray icon -- portable way? zirias Programming 5 07-30-2010 08:45 AM
Don't show boot messages during Clonezilla boot-up. Splash screen? Perd Linux - Newbie 4 07-18-2010 02:49 PM
compiz tray icon gbj Linux - Desktop 2 01-05-2007 02:19 AM
how to move anyprog to tray icon safrout Linux - General 6 09-20-2004 01:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration