• Post Reply Bookmark Topic Watch Topic
  • New Topic

Console window which stays on top  RSS feed

 
Alexandr Shvedov
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
We need to start cmd.exe window from our swing application. There is no problems with that. We us next code



The problem is that user must see what happened in console when working with swing application. How can I do so that cmd window stay on top of the swing application? Another words it shouldn't be hidden by main app window when user clicks on it. It seems to me that I should set some window attributes. How can I do that? Or maybe there is a way to forward outputStream from working program to JTextArea, while this program is working?
Thank you.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime.exec() returns a Process object that you can get input, output, and error streams from, and you can redirect these to/from a text area.

You could also call setState(Frame.ICONIFIED) or setVisible(false) on your frame once the console is launched to hide the frame, then use the waitFor() method of Process to listen for the end of the process, and call setState(Frame.NORMAL) or setVisible(true) to return your frame once the console process is done.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've got three choices:

1. Use Java 1.5 (5.0) and make your console window extend "Window" (or JWindow) and call: "setAlwaysOnTop(boolean alwaysOnTop)"

2. When the console window pops up, you resize that and the main app window to fit side-by-side on the screen (see Microsoft Word and how they do this when you choose "help" for an example)

3. Use JNI. This means you'll need code for each OS it'll be installed on. If on Windows 2k/XP, look at:
a. JAWT and JAWT_Win32DrawingSurfaceInfo to get hwnd
b. Call: SetWindowPos( hwnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOWIZE )

Those are your options.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!