2

I make Java programs, many of which require input from the command line before they actually open a window. When I'm using the Terminal in fullscreen mode and I run java Program, it jumps over to an open desktop and then does nothing, causing me to have to switch back to the Terminal to do the stuff it's asking and then switch over. I know it's a really simple fix of not using fullscreen but is there any way to let the focus stay on the command line until the program is ready to open the window?

2

I'd recommend not allocating any GUI elements until after the command line input is finished.

If you run your app from a non-fullscreen Terminal, you'll probably notice that the app launches in the Dock (even if no windows appear) before you finish entering your command line stuff. This is probably what's causing the Space-switch.

  • Yeah I don't run the constructor until the command line input is finished but it still opens the app in the dock and switches spaces. – CaldwellYSR Mar 21 '12 at 23:38
  • What constructor don't you run? If it's opening in the Dock, then new Frame() or new Dialog() or some such is being called; if not by you, then by some other code you call. – CajunLuke Mar 21 '12 at 23:41
  • Well I THINK it's a JFrame constructor.... I'm using a third party library. I haven't noticed if the issue occurs when I make my own GUI's, I'll check it and let you know. – CaldwellYSR Mar 21 '12 at 23:51
  • Even with regular JFrame constructors it opens in the dock before getting input. – CaldwellYSR Mar 21 '12 at 23:59
  • Is there any way you can get your input before calling the other code? – CajunLuke Mar 22 '12 at 0:16
0

@CajunLuke is right, Apple's Java Virtual Machine prepares the desktop to display a peer component, even before setVisible() launches the event dispatch thread. It's a feature, most of the time. One way to achieve the desired effect is to launch the GUI component in a separate JVM, as shown here using ProcessBuilder.

See also Using Headless Mode in the Java SE Platform.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .