I have a JApplet which is used for chat. I would like to make it possible that when the applet is minimised and a chat message is received by the user, the minimised window becomes orange (and thus shows the user that something has occurred).
How is it possible to make the applet do this?
Thanks,
Tim
You may have access to the system tray in an applet (I'm not sure). Have a look at the java.awt.SystemTray class - the in-tray lets you pop up messages to the user.
Alternatively you could attempt to cause the Window's toFront method to be called or to "maximize" using the setSize methods (again, I'm not sure what effect this has in an applet). I suspect that the toFront method will be a good bet
Another option I'd look at is raising a JDialog. The presence of this may cause the OS to draw attention to the minimized applet. You could listen to window events representing the screen un-minimizing to clear the dialog so that the user never knew it was there.
Related
I'm currently programming a little Java game and I use the JOptionPane class to alert the user if an IOException is thrown. I'd like to know how to prevent the option pane from being "closed" by clicking anywhere else, e.g. on the desktop, because it actually doesn't end the Java process.
If you want to have you window always visible (regardless of the other windows) there is an option called alwaysOnTop, when you set that to true, the host OS will try to honour that directive displaying the window always.
Try to see if these posts helps:
JOptionPane displays behind the parent JFrame
how to show JOptionPane on the top of all windows
Im trying to make a java program that will popup/notify me to stop what I am currently doing and do something. more like a reminder. My question is how will I make a pop up in java.
I found this docs, but dont know how to implement for the parent component.
JOptionPane.showMessageDialog(??,"this is a modal dialog.");
The answer depends, do you have a parent component (like a JFrame or other component) or are you simply display the JOptionPane independently?
If you are simply displaying the JOptionPane independently, you can simply pass it null.
If you are displaying the JOptionPane as part of a large application, with windows and other components, you can simply pass it a reference of what ever component you want the JOptionPane to displayed relative to, such as the window or most accessible container/component
The parent argument (if supplied) simply allows the dialog to act as a modal (blocking) dialog for the window which contains the supplied component. This requires the user to have to dismiss the dialog before they can continue to interact with the parent window/component
Take a closer look at How to Make Dialogs for more details
I want to set a window invisible but focused for a fraction of seconds.
I'm writing a key board emulator using Robot class as a part of project for detecting key loggers.
Keyboard emulator should not disrupt the normal work of the user, so I want to set a hidden window focused for a short span so that the keys entered by the robot class received by the hidden window instead of normal user applications.
Is there any way to do this in Java when window is actually invisible? How to do this? at least in windows platform?
How about transparent full screen window in case the above thing is not possible?
My base paper: http://www.atlantis-press.com/php/download_paper.php?id=9980
Is there any way to do this in Java when window is actually invisible?
No. Not in pure Java at least.
How about transparent full screen window in case the above thing is not possible?
A transparent window does not receive events. So again, no.
My program consists of 3 main 'sections'. Main function, Login form and App form. The main function should do something like: Open Login form, wait for it to close, then open App form. I can't get the waiting part to work, or rather, I don't know how I would go around doing that.
I was told by someone to use a JDialog instead and use setModal(true), but with that approach the Login form wouldn't appear on the taskbar, which is terrible in my opinion.
Another thing I considered was to open the App from inside the Login after it closes, but that feels like bad design since that'd make the Login form non-reusable.
So, please, what would you suggest?
Why must the login appear on the task bar, since the main app will be there, and you don't want more than one task bar item for an individual program. Your best option may be to use a modal JDialog.
Another option is to use CardLayout to swap "views".
A third option is to use a JFrame if you must but attach a listener to it, a WindowListener I believe, to respond to its close event.
Regardless of which route you go, your login gui should be a JPanel so that you can place it anywhere you wish and then change your mind later.
I'm hoping to close the popped out applet to return it to the browser window where it was dragged out of. I'm doing this so that when the user moves from the applet's page, the applet doesn't remain open to them.
I've tried the destroy() method, the stop() method, as well as trying to call removeAll() on the container of the window, though I'm not sure I did that correctly.
Here's part of my code that gets called when the user wants to cancel the applet's execution. Instead of closing the applet, however, I just have it so the applet becomes invisible, though that leaves a big, blank window where the dragged out applet used to be and it's left to the user to close that.
function Cancel(){
document.appletName.cancel();
document.appletName.setVisible(false);
window.location="/*newURL*/";
}
I want that window to close on its own, but I'm not sure what to call.
I don't have access to the source code of the applet, unfortunately, so this has to be done from the browser.
So there is no way to do this in a "zen" sort of way, but having the applet output some sort of informative message that it needs to be closed as well as using setEnable(false) to make it so they can't interact with it forces the user to have to close the applet. Not the most user friendly, but definitely a good way to go if you have users that will insist on dragging the applet out of their window.