1


I'm writing a Java program which checks some statistics of my Web site. The program should point out an alert if there are some issues with the site. Since I'm working with a Windows Vista machine I thought the simplest thing would be to create a Task from Windows Scheduler which fires every n minutes.
Strangely enough, the Task Scheduler is not able to display Java GUI. The program just stops (either running with java or javaw) and does not display anything.
Here's a minimal example:

import javax.swing.JOptionPane;
public class Test {
public static void main(String[] args) {
    try {
        JOptionPane.showMessageDialog(null, "Message text", "Title", JOptionPane.ERROR_MESSAGE);
        System.out.println("Done");

    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

I've tried also with some other Swing components but it just does not display anything. Seems it's missing the graphical interface. Any clue ? Thanks Max

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Max Korn
  • 275
  • 7
  • 18
  • How did you specify the application and arguments in Windows task scheduler? – Guillaume Polet Jan 25 '13 at 09:38
  • Of special interest is which user is running the task. Maybe your program is showing the Dialog to `LocalSystem` or something like that. – SJuan76 Jan 25 '13 at 09:41
  • I'm launching the program using a batch file which contains "C:\Program Files\Java\jre6\bin\javaw" -classpath myapp.jar Test I've checked that the program is actually launched (added a file log) but is unable to display GUI – Max Korn Jan 25 '13 at 10:14
  • @MaxKorn What is the working directory specified? It must be the directory containing the jar "myapp.jar". – Guillaume Polet Jan 25 '13 at 12:47
  • Thanks for the reply @Guillaume the working directory was specified in the Task manager options. However that Java app starts, it just cannot display Swing GUIs :-( – Max Korn Jan 25 '13 at 13:36

1 Answers1

2

there are two issue

  1. most important, JOptionPane block code executions untill event from JOptionPane is fired, simple this is basic property block code executions and waiting for users action

  2. JOptionPane must be invoked from Initial Thread, otherwise nothing happened, not is visible on the screen, or (MetalLookAndFeel) only Toolbar without content is visible on the screen (came from Native OS)

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Thanks for your reply. Tried with the example in http://docs.oracle.com/javase/7/docs/api/javax/swing/SwingUtilities.html#invokeAndWait%28java.lang.Runnable%29 However it does not display anything :-( – Max Korn Jan 25 '13 at 10:24
  • I'm never ever find_out the place for using `InvokeAndWait` (my view) in `Java6` and newer version, there must be another issue hidden in your code, maybe replace `JOptionPane` with plain `JDialog` could be dirty hack, but I'm doubt ... – mKorbel Jan 25 '13 at 10:27
  • To be honest, since I was not able to get it working, I have solved it by launching a browser new window (instead of a Java Swing GUI) which points to an Help Page. Thanks anyway for your help. – Max Korn Jan 25 '13 at 12:01