Right now I have a frame in full screen exclusive mode, which commands the whole screen. The panel has a button which launches the windows native calculator program (just for testing purposes). Is it possible to have that process start completely in the background? Right now I have this:
this.parent.setAlwaysOnTop(true);
try {
Process p = Runtime.getRuntime().exec("calc");
} catch (IOException e1) {
ErrorDialog error = new ErrorDialog("Error handling your shell action");
e1.printStackTrace();
System.exit(0);
}
this.parent.setAlwaysOnTop(false);
This DOES do what I need, but doesn't make it pretty. It "minimizes" my window first, then starts calc, then re-maximizes my window. It all happens quickly but stuff is flashing all over the place. Is it possible to make "calc" run in the background without touching my main window and making it completely seamless?
This is in principle a window manager specific thing, at least on X systems (like Linux and most other Unixes with a GUI).
Some window managers start new programs always in the background, always in the foreground, or even require the user to draw the window's area with the mouse. Others respect the wishes of the program being started.
Thus, you could have a look at the command line options of the program you are starting, maybe they have an option like "start minimized" or similar.
If you are using KDE (and the KDE window manager), you can use kstart --onbottom ... or kstart --minimize ... to start your program, which will put the window on the bottom of the stack, or start it minimized. (Have a look at the kstart options, you'll also want to use --window or --windowclass to indicate the window.)
Test it out in Linux, maybe it doesn't flicker there. If not many people will use it in Windows, flickering shouldn't be a big concern.
I don't think there's a Java-specific way to handle this, you're launching an external process. How it launches is up to the OS.
Related
In other words, how can I make it so that the window or screen that they are on is the only screen that they can interact with. For example, if the user wants to exit from the screen but then wants to go to another screen, well then they will have to exit from the exit window first before they can do anything else. A better example is when you open multiple windows in Windows and try to exit from another screen than the one you're on, it will make a beeping noise indicating that you can't do that. Something similar to that is what I'm trying to achieve
It's important to note that my program consists of java code, FXML and a little bit of CSS
If you just want a frame to block all other frames from receiving events, use a modal Dialog.
String cmd = "start calc.exe";
Process process = Runtime.getRuntime().exec(codeString);
I can call calculator out, but I wish to specify a accurate position like (200,300).
how can I rewrite my cmd String?
I know that java.awt.window can set a window or frame to the specific position.
Is there any method I can use to fill frame or window with my process?
There is no clean pure java solution because JDK does not provide API that can control non-java windows. So, if you want to can use JNI/JNA.
But I can suggest you a patch that will typically work.
Windows OS allows moving windows using keyboard. Try the following manually:
Win+R
type calc and press enter
press alt+space
press M
press enter
now use arrows to move the window. Press ESC to exit this mode.
All these actions can be implemented using java.awt.Robot.
So, you can run calculator and then immediately move its window where you want.
Well, this is not clear solution, but very simple one.
Expected Problems:
Alt+space is mapped to other, custom application
Other window that started together with calc overlaps it.
User will see that window is created somewhere and then quickly moved.
So, everything depends on how important all this for you. This solution is good as an exercise or demo but bad for real commercial application.
I have a Java application that reduce into the system tray when the red cross is pressed.
Whenever this happen, I display a message to inform the user that the application is still running in the system tray.
Here's the code for that :
...
#Override
public void windowClosing(WindowEvent e) {
try {
tray.add(trayIcon);
trayIcon.displayMessage("", "The application has been reduced
in the system tray, to stop it, press the \"Quit\" button",
TrayIcon.MessageType.WARNING);
setVisible(false);
} catch (AWTException ex) {
System.out.println("unable to add to tray");
}
}
...
For the moment, the message disappears if the user clicks on it.
I would like to set up a counter so the message would fade out after a couple of seconds even if nothing has been done.
Does anyone know a nice way to do it cause I can't seem to find any existing method for that.
EDIT
I have to correct my question, in fact, after testing it a little bit longer, it automatically fades out after, let's say, 7-8 seconds but I find it a little bit too long. Also, it only disappears if the user is executing an action (moving the mouse or typing on the keyboard)
So the new question would be : Is there a way to reduce the fade out time and change the message behaviour by configuring the Java application or is it inherent to Windows?
So the new question would be : Is there a way to reduce the fade out
time by configuring the Java application or is it inherent to Windows?
MSDN says in part How long to notify - In Windows Vista and later, notifications are displayed for a fixed duration of 9 seconds.
any changes is possible to maintain only on Windows size, but seems like is valid/applied for all messagess
you can to create own Traslucent JDialog (Transparency could be way too) placed programatically to the left bottom, fading out will be invoked from Swing Timer
I am trying to develop an application which responds to multiple digital pens (IRIS Pens) so that if any of the pen writes on paper; I relay the output to a single screen. Thus making a multi-input whiteboard for myself.
In Ubuntu these pens are recognized as mouse and thus can be handled in a similar manner as mouse events are handled.
So now what I plan to do is to handle these events in C/C++ using XLib and pass these events to a Java Swing application using JNI callback. I am able to do this but when the X11 window looses focus no events are transferred to the Swing frame. I also tried to use the root window in X11 but it does not seem to work.
Any help would be really appreciated. Thanking you in advance.
How about maximizing the C/X11 window in front of the Java one, and making it transparent? You should be able to see the Java window while still focusing on the C/X11 one.
Since you are using Ubuntu, you can achieve this using the "Opacity, brightness and saturation" plugin for Compiz. It is in the compiz-plugins-main package, and you can activate it with Compiz Settings Manager (from the compizconfig-settings-manager package). When you activate the plugin, alt+wheel is bound by default to change the transparency of the focused window.
Try reading the mouse directly. I don't remember the exact location, but you should find it in something like '/dev/input/mouseX', where X is the number of your device, ranging from 0 to n-1 devices..
When you read the packet, your application should block until the mouse moves and then your read function will return a raw mouse packet which describes the delta (which is probably more useful then the screen coordinates, in your case) and the mouse button statuses.
The raw packet can be decoded as described here: http://www.computer-engineering.org/ps2mouse/
Create a modal dialog and set it to XmDIALOG_SYSTEM_MODAL (the actual name of the property depends on your toolkit: Motif, Gtk, Qt, ...). Dialogs like this block the whole display and can never loose focus.
The drawback is of course that you can't do anything else while this dialog is on the screen.
This entry in the X11 FAQ might help.
In my Swing application, I'm using a custom module to record a screen cast.
However, I'm a bit hung up on when to force the recording to stop. Right now, I check to see if the user still wishes to record (meaning that they haven't clicked the 'stop' button) and if the application is still open (closing the application causes the recording to stop gracefully).
The problem is that the recording will continue if the application gets pushed behind other apps or minimized, causing recording of 'junk'. I need the recording to stop when the application is no longer 'on top' of the screen. Using the application's focus doesn't seem to work due to other dialogs and things popping up.
Suggestions?
You may want to try adding a WindowListener and override the windowDeactivated() event, which should get called when the frame is no longer the "active window" according to the operating system.
UPDATE:
If you are conscientious about making sure that your child dialogs and windows are owned by your application (making sure you pass in your application frame as the owner), then you could make your WindowListener do something like this:
public void windowDeactivated(WindowEvent e) {
if(e.getOppositeWindow() == null){
// will be null when another application window gets activated, stop recording
}
for(Window w : appFrame.getOwnedWindows()){
if(w.equals(e.getOppositeWindow())){
// one of the windows owned by the frame is active, don't stop recording
}
}
}
Then you will be able to determine if the window focus has left your application altogether or if the focus has just changed to a different child window/dialog.