Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies: 11 - Pages: 1  
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

Why is Tray Icon AWT Based

At 9:25 AM on Jun 21, 2007, Jens Hohl wrote:

Writing desktop applications which are deeply integrated into the desktop from my point of view are hard to implement. I can use Actions and Icons also doing more cool stuff for fancy apps.

The AWT Tray Icon in Java 6 is nice, but i ask my self why it is completely AWT Based?
1 . At 9:38 AM on Jun 21, 2007, Brian Matzon wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

and why is it an issue that it's AWT based?
2 . At 10:24 AM on Jun 21, 2007, Ronald Miura wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

AWT is a 'OS integration layer'. Java2D, Robot, Printing, Imaging. It's the natural place for TrayIcon.
3 . At 11:22 AM on Jun 21, 2007, Jens Hohl wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

The Popup looks ugly also i cannot use any Action Interface.
www.mac-systems.de | https://multikulti.dev.java.net
4 . At 2:56 PM on Jun 21, 2007, cowwoc wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

Take a look at the popup menu for Yahoo Messenger. Now imagine what you could do with a Swing popup menu.

There is something to be said for enabling Swing popup menus for tray icons. The problem is that it is impossible to implement without JDK-side support. The problem is that Swing popup menus refuse to render themselves on top of the "taskbar" so when you right-click on an icon the menu pops many pixels above the actual pop-up position. The problem wouldn't be as bad if Sun somehow enabled Swing popups to render themselves on top of the taskbar if explicitly requested.

Granted this isn't a very compelling use-case but I had one a few months back and I forgot it :) Hopefully I will recall it soon so I can post it here :)

Gili
5 . At 3:15 PM on Jun 21, 2007, Derek Smith wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

i believe this has to do with mixing light weight and heavy weight components.

you can force a popup to be a heavy weight component though.

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JPopupMenu.html#setLightWeightPopupEnabled(boolean)
http://www.programmersbible.com - Online resource for programmers
6 . At 5:22 PM on Jun 21, 2007, Jan Erik wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

JFC support is broken.. or was never completed.

This works.. but it throws exceptions, sometimes require two clicks on the icon to close the popup and only works 100% if you click on the JFrame after a popup.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.teppefall.ds.console.Console;
import com.teppefall.ds.util.View;
 
public class TestSystemTray {
 
	static JFrame owner;
	static JPopupMenu jfcPopup;
	
	public static void main(String[] args) {
		TrayIcon trayIcon = null;
		if (SystemTray.isSupported()) {
		    SystemTray tray = SystemTray.getSystemTray();
		    Image image = new ImageIcon(TestSystemTray.class.getResource("/images/teppefall.png")).getImage();
		    owner = View.asApplication("JFC/SystemTray bug", new JLabel("Press here after popup"));
		    jfcPopup = new JPopupMenu("JFC");
		    jfcPopup.add(new JMenuItem("Exit") {{
		    	addActionListener(new ActionListener() {
		    		public void actionPerformed(ActionEvent e) {
			        	Console.info(this, e);
			        	System.exit(0);
		    		}
		    	}
	    		);
		    }});
		    trayIcon = new TrayIcon(image, "Tray Icon");
		    trayIcon.setImageAutoSize(true);
		    trayIcon.addActionListener(new ActionListener() {
		        public void actionPerformed(ActionEvent e) {
		        	Console.info(this, e);
		        	//System.exit(0);
		        	jfcPopup.setVisible(false);
		        }
		    });
		    trayIcon.addMouseListener(new MouseAdapter() {
		    	public void mouseReleased(MouseEvent e) {
		    		jfcPopup.setVisible(false);
		    		if(e.isPopupTrigger()) {
		    			jfcPopup.setInvoker(owner);
		    			jfcPopup.setLocation(e.getX(), e.getY());
		                jfcPopup.setVisible(true);
		    		}
		    	}
		    	public void mousePressed(MouseEvent e) {
		    		mouseReleased(e);
		    	}
		    });
		    try {
		        tray.add(trayIcon);
			    //trayIcon.displayMessage("Teppefall", "Says hi !", MessageType.INFO);
		    } catch (AWTException e) {
		    	Console.warn(TestSystemTray.class, e);
		    }
		} else {
		}
	}
}

The setInvoker idea I got from this:
http://weblogs.java.net/blog/ixmal/archive/2006/05/using_jpopupmen.html

Don't know if makes any difference though. The custom imports are from Darkstar:
http://us.teppefall.com/download.jsp

You can also try:
http://jeans.studentenweb.org/java/trayicon/trayicon.html
http://www.jpackages.com/jtray/
https://jdic.dev.java.net/ (as you mentioned)
http://labs.teppefall.com
7 . At 6:36 PM on Jun 21, 2007, cowwoc wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

Last I checked (back in Java 5) this had nothing to do with lightweight vs heavyweight but rather JPopupMenu had specific code inside it that ensured that its location would never overlap the taskbar. This is "by design".

Gili
8 . At 9:35 AM on Jun 23, 2007, Jens Hohl wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

Well, may someone from the AWT / Swing Team can say something about that ?

For me it is also an Issue that the Popup will not be in the Look and Feel of the Application. To say it in SUNISH: I cannot create an Nifty Client !

And for the posted code above: This is no solution as my experience shows often that any dll which is not that nessesary should be avoided as there can be issues on Clients resulting in crashes.

- jens
www.mac-systems.de | https://multikulti.dev.java.net
9 . At 6:52 AM on Jun 24, 2007, Sébastien wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

Hi.

I was disappointed too when I first tried to use the new tray icon feature of Java 6, I wanted nice looking icons in my JPopupMenu until I realized we could only use PopupMenu :(

I don't know the exact reason why it is now based on AWT, but I saw a bug report about this some time ago. As they explain, there is a work around for it (JPopupMenu displayed over the tray icon), but it is not really great.

It seems they'll be looking to it:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6285881


Have a nice day.
10 . At 10:04 AM on Jun 26, 2007, Clemens Eisserer DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

> And for the posted code above: This is no solution as
> my experience shows often that any dll which is not
> that nessesary should be avoided as there can be
> issues on Clients resulting in crashes.

Well from this point of view - should we develop software at all ;)
However of course I agree that just for such small enhancements native code is a very high price.

lg Clemens
11 . At 11:02 PM on Nov 28, 2007, Jens Hohl wrote:
  Click to reply to this thread Reply

Re: Why is Tray Icon AWT Based

I written some small Test Code which fits more my needs to do such Popup with Swing, it is 100% Java 6 based without any dll needed.

See http://forum.javacore.de/viewtopic.php?p=33877#33877
for more...

Best regards,
Jens
www.mac-systems.de | https://multikulti.dev.java.net

thread.rss_message