private void configureSystemTray() {
	    window.addWindowStateListener(new WindowStateListener() {

	            public void windowStateChanged(WindowEvent e) {
	                if (e.getNewState() == JFrame.ICONIFIED) {
	                    try {
	                        jTrayIconUI.addIconTray(window,wasUpdate);
	                        System.out.println("added to SystemTray");
	                    } catch (Exception ex) {
	                        System.out.println("unable to add to tray");
	                    }
	                }
	                if(e.getNewState() == WindowEvent.WINDOW_CLOSING){
	                   try {
	            	   jTrayIconUI.addIconTray(window,wasUpdate);
	                        System.out.println("added to SystemTray");
	                    } catch (Exception ex) {
	                        System.out.println("unable to add to system tray");
	                    }
	                }
	                if (e.getNewState() == 7) {
	                    try {
	                        jTrayIconUI.addIconTray(window,wasUpdate);
	                        System.out.println("added to SystemTray");
	                    } catch (Exception ex) {
	                        System.out.println("unable to add to system tray");
	                    }
	                }
	                if (e.getNewState() == JFrame.MAXIMIZED_BOTH) {
	                    jTrayIconUI.removeIconTray(window);
	                    System.out.println("Tray icon removed");
	                }
	                if (e.getNewState() == JFrame.NORMAL) {
	            	 jTrayIconUI.removeIconTray(window);
	                    System.out.println("Tray icon removed");
	                }
	            }
	        });
	}