Restoring a JFrame from system Tray
Hi,
I am writing a small application to see new system tray api in java.
Currentlty i am facing a problem - My application minimizes to system tray correctly but when i restore it by clicking on to the tray icon it remains in the minimize state but i want it in restore state.
private void initTrayIcon()
Image image = Toolkit.getDefaultToolkit().getImage("tray.gif");
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
exitApplication();
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "Tray Demo", popup);
trayIcon.setImageAutoSize(true);
trayIcon.addMouseListener(new MouseAdapter()
public void mouseClicked(MouseEvent e)
//System.out.println("Tray Icon - Mouse clicked!");
setVisible(true);
}Code of constructor
initTrayIcon()
addWindowListener(new WindowAdapter()
public void windowDeiconified(WindowEvent e)
if (SystemTray.isSupported())
SystemTray tray = SystemTray.getSystemTray();
tray.remove(trayIcon);
setVisible(true);
requestFocus();
public void windowIconified(WindowEvent e)
try
if (SystemTray.isSupported())
SystemTray tray = SystemTray.getSystemTray();
tray.add(trayIcon);
//setExtendedState(ICONIFIED);
setVisible(false);
catch (AWTException ex)
System.err.println("TrayIcon could not be added.");
});
Here is complete code for those who are still facing this problem.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SystemTrayFinalExample extends JFrame
public SystemTrayFinalExample()
if(!SystemTray.isSupported())
JOptionPane.showMessageDialog(this,"Your system doesn't supports System Tray","ERROR",0);
System.exit(0);
initComponents();
private void initComponents()
setTitle("System Tray Demo");
setSize(300,200);
popupmenu = new PopupMenu();
menuitem1 = new MenuItem("Exit");
menuitem1.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent exx)
System.exit(0);
popupmenu.add(menuitem1);
trayicon = new TrayIcon(Toolkit.getDefaultToolkit().getImage("computer.png"),"System Tray Final Example",popupmenu);
trayicon.addMouseListener(new MouseAdapter()
public void mouseClicked(MouseEvent e)
if(e.getButton() == MouseEvent.BUTTON1)
setVisible(true);
setExtendedState(JFrame.NORMAL);
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
public void windowIconified(WindowEvent ex)
setVisible(false);
try
SystemTray.getSystemTray().add(trayicon);
catch(AWTException e)
e.printStackTrace();
trayicon.displayMessage("Message","Click this icon to restore window",TrayIcon.MessageType.INFO);
public void windowDeiconified(WindowEvent ex)
SystemTray.getSystemTray().remove(trayicon);
public static void main(String args[])
new SystemTrayFinalExample().setVisible(true);
private TrayIcon trayicon;
private PopupMenu popupmenu;
private MenuItem menuitem1;
}
Similar Messages
-
Skype freezes when I open it up from system tray a...
Whenever I try to open skype from system tray and when I start a chat with someone, Skype freezes and I have to wait for like 20-30 seconds before I am able to chat. I have a freshly installed windows 7 x64 and the newest skype version.
Same story for me! Ususally the other party can hear and see me before my end starts working. Except sometimes takes minutes for Skype to stabilize before I can use it. Then it seems to work. Using Win 7 and Skype 7.1.0.105. The problem has existed since installing 7.1. Makes using Skype a real pain!
Internet Explorer is resident on computer, but I use Foxfire for browsing. -
[SOLVED]KDE does not remember window state, restoring from System Tray
Hi,
I'm facing a problem with some KDE applications that dock in the system tray, like Amarok and Konversation. I like to keep these apps maximized. But when I restore them from the system tray, they always revert back to their original, unmaximized size. Is there any workaround or fix for this?
Using KDE 4.3.4-2 (not KDEmod)
Thanks.
Last edited by codemon (2009-12-08 08:56:16)Funny thing happened. I tried out your suggestion for my Firefox window, which would always start in an un-maximized state. It worked perfectly. Then I opened up Konversation and Amarok, and found that they properly remember the window state now!
Thanks for the help. -
Bootcamp Icon missing from system tray...
On the 1st computer (iMac) that I installed BootCamp with Win 7, I have an icon in the lower left system tray for changing the booting choice.
Today I installed BootCamp on my wife's new Mac Mini and the icon is missing from the system tray. While it was about 6 weeks ago that I put BootCamp on my iMac, I don't remember doing anything that cause the Windows system tray to display the boot choice icon for BootCamp/Win 7.
Anyone have an idea about how I can get that icon to appear on the Mac Mini.
Both systems are running Snow Leopard with the latest software.Macaby there are two separate components of Boot Camp. First is Assistant which runs on the Mac side of things from OS X. It creates/deletes the Windows partition which is necessary to install Windows. Next the Boot Camp Panel software which is installed once you have successfully installed and are running Windows. It allows tweaking of the Apple hardware from within Windows. It is installed using the OS X disc and does not jeopardize your installed Windows OS in any way. This disc also contains the hardware driver necessary to optimize the hardware in Windows. In my experience this disc has never started via autorun so you will most likely have to locate the Boot Camp folder and run the setup.exe file manually.
Don't know how much your wife uses Windows but if it's running well enough then you may want to leave it alone. Check device manager in Windows for any red or yellow punctuation marks. This will indicate a potential driver issue in Windows. Also check the Windows Experience Index for performance issues. A 1 anywhere indicates a driver issue. If you have no driver issues and Windows is running well enough you may want to leave it at that. -
How to remove Application icon from system tray on uninstalling the application
Hello Friends
Is there any way to remove a system tray icon when i unistalled the application?
i am making a desktop application but i am facing a problem that during uninstallation of that application it remains on the system tray.So can any body guide me any event which fire on unistallaion of application so that i can remove the application manually using cllosing event.please help me out from this poblem i am totally confused.
Thanks and Regards
Vineet OshoI have same problem with you but I haven't find an answer for that. Did you have your answer for the problem?
Thanks! -
Disappearing Z from System Tray
I wish the Z didn't always disappear from they system tray. It has been an issue for us on 10.3.1, 10.3.3 and 10.3.4. Sure would like it if that bugger was self healing at the least, would be even better if it was stable and didn't need to self-heal.
heavyhaze.Since you have serveral issues..... Have you opened incicents? If yes,
then please give me the SR numbers and I will talk to Novell.
Anders Gustafsson (NKP)
The Aaland Islands (N60 E20)
Novell has a new enhancement request system,
or what is now known as the requirement portal.
If customers would like to give input in the upcoming
releases of Novell products then they should go to
http://www.novell.com/rms -
Updated my K450e to Windows 10, Realtek Audio Manager icon missing from system tray
When my K450e was using Windows 8 and 8.1, there was a red Realtek AudioHD Manager icon in my system tray. Now that I've updated the K450e to Windows 10, there is no Realtek Audio Manager icon in my system tray (or control panel) anymore. I've tried installing the Realtek Audio software both from the Lenovo download site for Windows 10, and also from the Realtek site. This has not helped. On the up side, the computer's audio is working fine *smile*. Any ideas what I might try to get the Realtek AudioHD manager icon back in the system tray for Windows 10? Thanks!
Macaby there are two separate components of Boot Camp. First is Assistant which runs on the Mac side of things from OS X. It creates/deletes the Windows partition which is necessary to install Windows. Next the Boot Camp Panel software which is installed once you have successfully installed and are running Windows. It allows tweaking of the Apple hardware from within Windows. It is installed using the OS X disc and does not jeopardize your installed Windows OS in any way. This disc also contains the hardware driver necessary to optimize the hardware in Windows. In my experience this disc has never started via autorun so you will most likely have to locate the Boot Camp folder and run the setup.exe file manually.
Don't know how much your wife uses Windows but if it's running well enough then you may want to leave it alone. Check device manager in Windows for any red or yellow punctuation marks. This will indicate a potential driver issue in Windows. Also check the Windows Experience Index for performance issues. A 1 anywhere indicates a driver issue. If you have no driver issues and Windows is running well enough you may want to leave it at that. -
Plasma crashed today and I lost, so called, "Default panel". After restart, I manually added panel, added System tray widget on it but System tray is no more displaying icons of non KDE applications such Pidgin, Skype and DeaDBeeF. Tried to change icon theme, played with icons folder mentioned in topic https://bbs.archlinux.org/viewtopic.php?id=103689 but so far no luck. There are not even blank spaces instead of icons. If I add System tray widget to the desktop, it also don't have those icons on it and it have blank spaces instead, say, KNotes and Klipper.
Any help is appreciated.
Last edited by benke (2010-10-10 07:16:44)File ~/.kde4/share/config/plasma-desktop-appletsrc was corrupted. I backed up it, deleted, restarted KDE, new file is created. Need to tweak desktop again but icons are shown correctly.
http://forum.kde.org/viewtopic.php?f=66&t=87660 -
Remote Icon Missing from System Tray
I just installed zenworks and it doesn't display the icon in the system tray how do i get this to display?
Thanks
Aron
Aron Hardie
Net Admin
Great Western ServicesGo to the Counting Crows concert with Walter(Matt Damon) and he will
explain it to you...
Bryan
> Aron Hardie wrote:
> > I just installed zenworks and it doesn't display the icon in the
system
> > tray how do i get this to display?
> >
> > Thanks
> > Aron
> >
> > Aron Hardie
> > Net Admin
> > Great Western Services
>
> Did you check the option to have Application Explorer startup with
> Windows? If not, you can start it by going to Start->Programs-
>Zenworks
> For Desktops 4->Application Explorer. -
Adobe Tracker icon can't be removed from system tray??
I've been using Adobe Acrobat to created PDFs and do a shared review on a server. It's been great. Today someone asked me how to get rid of the Tracker icon that showed up in their system tray. It doesn't go away! I tried turning off notifications and hiding the icon, but it comes back after restarting. Any ideas?? I don't want people to stop reviewing my material because they don't want this Tracker to show up on their machines.
I am not sure where the startup is located, in the registry or one of the startup files. You can try to find out by going to START>Run>msconfig. You can search for where the file is being setup for starting.
-
Restoring user accounts from system install backup directory
Hi,
I had some kind of disk problem that forced me to reload tiger. When tiger intalled it backed up all of the user directries. After the new install booted up I can not figure out how to restore all of my user accounts from this backup directory. Maybe I am making it too hard (ex PC user). The migtration utility only wants to restore off a Mac or different volume. Any suggestions?
Thanks
imac g4 800 Mac OS X (10.4.6)If you did an Archive & Install, then you should have selected the saving user and network settings. Otherwise, everything was put into the Previous System folder. IIRC, you need to recreate the users, using the exact same username and password combinations. Then, log into each account, open the corresponding folder within the Previous System/Users/ directory and transfer everything from the old account to current account.
-
Sound manager from system tray
Hi, I disabled the tray icon, and can't seem to get it back, or at least get into the manager so I can adjust the equalizer from it and all. Any help would be great. Running 3820 with win xp home. Anything else that would help, let me know. I have searched soundman or whatever the name of it was and couldn't still find it, so i'm stumped, thanks in advance....
ok, now i see it in my control panel, i never thought of changing it to the classic view until you said that, but yeah, the first question, it is a via board. I will see the run option now......
well, couldn't get the sstray to work. even tried stray. at least i got it now from the contol panel, thanks guys for your help and replies. i never thought of the classic view, because I'm always used to the category mode, anyways, thanks for opening up my eyes. -
Why my system tray application terminates when JFrame is closed???
Hi,
I am using JDK 1.6 with Netbeans 5.5 and currently trying to make an system tray application. I have one main class which runs as a system tray application and one JFrame class which will be shown when user selects a menu item from system tray. So far so good but a small problem. When the JFrame form is closed, my system tray application also closes. Can somebody tell me what am I missing?
Thanksset the DefaultCloseOperation of the JFrame to DISPOSE_ON_CLOSE instead of EXIT_ON_CLOSE
db -
So, I am developing an application that utilizes a system tray icon.
It's all pretty standard: when you click close, it hides the window and puts a system tray icon in the system tray, when you right click the tray icon, it gives you a menu with options to restore the window or to exit, and if you double left click the icon, it restores the window.
Also, any time you restore the window, the system tray icon is removed.
All that stuff works great, its just that instead of putting the image that I want as the icon, the icon is just blank - transparent - nothing. There is a space where it should be, but the image just isn't there.
The image I'm using is a gif that measures 240 x 240 pixels, and has transparency.
When the window is hidden, the program does this:
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("TrayIcon could not be added.");
}to add the icon to the tray.
Here's my initialization code. It's in a method called initSysTray, which is called once in the window's constructor.
if (SystemTray.isSupported()) {
tray = SystemTray.getSystemTray();
//image that will be used for System tray Icon
ImageIcon image = new ImageIcon("Icon2.gif");
//action listener for the exit menu option
//that is part of the tray icon's pop-up menu
//it ends the application
ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Exiting...");
System.exit(0);
//action listener for the restore menu option
//that is part of the tray icon's pop-up menu
//it unhides the window and removes the tray icon
ActionListener unHideListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Unhiding");
setVisible(true);
tray.remove(trayIcon);
//Action Listener that recieves events from tray icon
//basically if someone double clicks the tray icon
//then the window is restored
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Unhiding");
setVisible(true);
tray.remove(trayIcon);
//create the pop-up menu
PopupMenu popup = new PopupMenu();
//create the exit option
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
//create the restore option
MenuItem unHideItem = new MenuItem("Restore");
unHideItem.addActionListener(unHideListener);
//add the options to the menu
popup.add(unHideItem);
popup.add(defaultItem);
//create the tray icon
trayIcon = new TrayIcon(image.getImage(), "Bluetooth Remote by D Law", popup);
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
else{
System.out.println("System Tray not supported");
}So, any help with my dissapearing icon would be greatly appreciated.Hi, are you not suppose to catch possible exceptions thrown by the TrayIcon constructor? :
//create the tray icon
trayIcon = new TrayIcon(image.getImage(), "Bluetooth Remote by D Law", popup);Try surrounding this line of code with a try and catch block. Referring to the API
documentation, there are 4 possible exceptions that can be thrown. Errors may
be present there, and we need a way to identify it. :) -
Skydrive (OneDrive) Icon in System Tray Caused by KB2849636
KB2849636 installs an update that puts a Skydrive icon in the system tray, and there is no way (that I know of) to remove it. I've since removed KB2849636 but assume It'll stick around for a while, has anybody come up with a solution that allows you to disable
this icon?Hi,
If this issue still persists, as a workaround, we may just remove this icon from system tray:
Change how icons appear in the notification area
http://windows.microsoft.com/en-in/windows7/change-how-icons-appear-in-the-notification-area
Alex Zhao
TechNet Community Support
Maybe you are looking for
-
Port Forwarding / Mapping is not working !?
I've tried everything, searched on Google and nothing seems to work ! First of all, let me explain my problem. I have a Time Capsule connected to my Modem. From my Time Capsule I have a Airport Extreme connected by ethernet on my second floor. So wha
-
How to create multi chart dashboard in SharePoint 2013?
Hi All, I would like to have a dashboard in SharePoint 2013 like this: Here, project details are from a list "Project", Budget consumption from a list "Budget". Different project should mention as option in tab like Project1, project2, project3. If i
-
I have redeemed a code a few months back and bought some music. I have credit left but am still being asked for a redemption code. I no longer have the code, but according to apples help topics I do not need it. How do I purchase without the code?
-
Oracle 9i and Linux 7.2 Suse
Hi: Please let me know if i,m right... I,m newie and i would like to install Oracle 9i Database over Linux 7.2.Do i have to download the linux vesion of the database? Somebody knows if there is an installation guide for this? Where can i get the data
-
Hello My SCCM 2012 client not appear in SCCM Console LocationServices and ClientLocation is OK and the computer is assigned to Site Help ?? Thank you . Regards