TrayIcon with hidden console

1

I have a program in java , with no graphical interface, only console. The only output commands are System.out.println() . I implemented it so that the program had a trayicon. The problem is that I just want the active trayicon when executing and is currently executing tray + console.

I tried, but to no avail:

Runnable runner = new Runnable() {
            public void run() {
              if (SystemTray.isSupported()) {
                SystemTray tray = SystemTray.getSystemTray();
                Image image = Toolkit.getDefaultToolkit().getImage("C:\logo.png");
                final PopupMenu popup = new PopupMenu();
                MenuItem aboutItem = new MenuItem("WS");
                Menu displayMenu = new Menu("Hora de Inicio");                   
                MenuItem hora = new MenuItem(tempo);
                popup.add(aboutItem);
                popup.addSeparator();
                popup.add(displayMenu);
                displayMenu.add(hora);
                TrayIcon trayIcon = new TrayIcon(image, "WebService", popup);
                trayIcon.setImageAutoSize(true); 
                try {
                  tray.add(trayIcon);
                  this.setVisible(false);
                  trayIcon.displayMessage("Aviso!", "Programa continua em execução...", TrayIcon.MessageType.INFO);
                } catch (AWTException e) {
                  System.err.println("Não pode adicionar a tray");
                }
              } else {
                System.err.println("Tray indisponível");
              }
            }
          };
          EventQueue.invokeLater(runner);   

How do I run this application:

After performing the build in NetBeans I simply use " java -jar ws.jar " or I use Launch4j, I create a exe and double click. It displays a black window (application default + windows

What I would like would be to hide the screen above and leave it only via tray (do not run the risk of someone closing the console and stopping the application)

    
asked by anonymous 29.12.2016 / 14:20

1 answer

4

From what I saw you are no longer having problems with TrayIcon, you just want a windows console window not waiting for the end of your program to run. To resolve this constraint you can use the javaw command to call your class, instead of the java command.

From the documentation :

  

The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you do not want to command prompt window to appear. The javaw launcher will, however, display a dialog box with error information if launch fails.

Free translation:

  

The javaw command is identical to the java command, except that with javaw there is no associated console window. Use javaw when you do not want a command window to appear. The javaw launcher will, however, pop up a dialog with error information if the call fails.

    
29.12.2016 / 15:50