Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
    
Look here at Stack Overflow for the programming-related section of the answer. stackoverflow.com/questions/9832252/… –  CajunLuke Mar 24 '12 at 5:16

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
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

@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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.