I created a swing application on Windows OS. One of my JDialog (whose window is parentJFrame) shows a JOptionPane.
JOptionPane.showMessageDialog(parentJFrame, "I am a JOption"); .
At the run time, the parentJFrame setAlwaysOnTop(true) . Even though it has set alwaysOnTop-TRUE, the JOptionPane appeares on the parentJFrame on Windows OS. but When I ran it on Linux OS,JOptionPane displays behind the parentJFrame.(May be the reason is that parentJFrame alwyasOnTop is true, but how JRE runs the same application in different ways for diffrent OS s ?) How can I get it on the top of parentJFrame in Linux.? This is urgent please..
When a 'alwaysOnTop-true' component shows a JOptionPane, JOptionPane appears behind the component in Linux.. :( . But this handled well in Windows OS. JOptionPane is showed on the top of the component which is set 'alwaysOnTop-true' . It seemed that, there is a conflict Showing components on the desktop screen in Linux OS.. I m not sure so. But I guess it.
Linux OS has Oracle JDK and JRE 7
The behaviour you see on Linux is in accordance with the API specification. This is what it says for Window.setAlwaysOnTop():
If there are multiple always-on-top windows, their relative order is unspecified and platform dependent.
And also:
All windows owned by an always-on-top window inherit this state and automatically become always-on-top.
Which would explain why the JDialog that's at the heart of JOptionPane also has "always on top" status. Seems that on Windows by chance it works as you expected, but really you're asking Swing to do something impossible: To show the parent "always above other windows", but also to show the dialog on top of it.
Here's a possible workaround: Place the dialog next to the parent, so that while it's under it on the z-axis, the user will still see it:
JDialog dialog = new JOptionPane("Message").createDialog(parent, "Title");
Point dialogLoc = dialog.getLocation();
Point parentLoc = parent.getLocation();
dialog.setLocation(parentLoc.x + parent.getWidth(), dialogLoc.y);
dialog.setVisible(true);
Do note that there is no single "Linux OS", especially when it comes to window management - there are lots of different desktop environments and window managers that behave in widely different ways when it comes to window ordering and visibility, often deliberately.
This is very Simple : write this line of code after the code which you want to show ddialog box:
JOptionPane optionPane = new JOptionPane("Reports are Generated");
JDialog dialog = optionPane.createDialog("Success!");
dialog.setAlwaysOnTop(this.isAlwaysOnTopSupported());
dialog.setVisible(true);
Dont change anything exept Strings in double quotes.
Related
I'm using Windows builder for create an application in Java. I create a frame with the login interface. What i want is that if the user insert correct information he will write something.
I don't want to open another JFrame I would like that the Login frame will be substitute with another one in order to have only one windows.
Could you tell me the correct object that I must use?
The best options are using either a JOptionPane or a JDialog
JOptionPane works as a message box, and can be customized to your linking and usage. For example, if what you wanna show is a sucessfully logged in message, you could use:
JOptionPane.ShowMessageDialog(null, "Logged in sucessfully", "Logged in", JOptionPane.INFORMATION_MESSAGE);
You can find out about each parameter here. It's a pretty complete documentation of the JOptionPane.
JDialog is another time of window used by Window Builder, and is works as a window that cannot be switched, a classic modal dialog. While this screen is in usage you cannot acess others (as your JFrame), unless you command it to close. And to use this you can simply create it as you would with your Frame. It's modality is set by default.
From what I get of your message the first option would be the best alternative, but that decision's up to you.
I highly recommend you to look into some Window Builder documentation before you'd resort to Stack Overflow. This would be helpfull, it explains everything you need to know about the usage of Window Builder's windows and it's funcionalities.
you can close your current frame by using the command
this.dispose();
this will just close your current window. Just make sure you open the other window too.
JFrame frame = new [yourClassname]();
that should work just fine :)
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
I have a JFrame that is basically nothing more than a few JProgressBars for a data conversion program that takes several hours to complete. My problem is that the window manager urgency hint gets activated every time I update a progress bar, which is really annoying to have in the corner of my eye all day. I do still want it in my taskbar to be able to check it quickly, so changing it to a JDialog doesn't help. How can I turn off the urgency hints?
If it helps, the program actually runs on Windows 7, java version 1.7.0, although I do a lot of debugging with mock data on a Linux box, so cross-platform solutions are preferred but not critical.
maybe nothing complicated, standards
1) setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
2) there no reason to dispay the JFrame, calling for setVisible(true) see point 5th.
3) System Tray Functionality in Java SE 6
4) you have to add JPopupMenu to the TrayIcon
5) if some events occured then
TrayIcon#displayMessage here you can notify for blablabla as "Aplication started", "for any Aplications Events", or whatever
or by using setVisible(true) display JFrame, but there would be better to search for JFrame#getExtendedState, reason just flashing with JFrame#ICONIFIED in the TaskBar
I have class InfoDialog which extends JDialog class in Java. I show InfoDialog while I am establishing SSH connection ( 5 or 6 seconds ) with info text. How to put focus on InfoDialog that user cannot do anything else until InfoDialog runaway ?
I don't think you can lock the entire OS, but you can definetly lock your application by setting it modal. See the API of JDialog or do something like this:
JDialog info = new JDialog();
info.setModal(true);
I think you are looking for Modality:
Modality defines whether
The new modality model enables the developer to scope, or limit, a dialog box's modality blocking.
The following modality types are supported in Java SE 6:
Modeless type — A modeless dialog box
does not block any other window while
it is visible.
Document-modal type —
A document-modal dialog box blocks all
windows from the same document, except
windows from its child hierarchy. In
this context, a document is a
hierarchy of windows that share a
common ancestor, called the document
root, which is the closest ancestor
window without an owner.
Application-modal type — An
application-modal dialog box blocks
all windows from the same application,
except windows from its child
hierarchy. If several applets are
launched in a browser environment, the
browser is allowed to treat them
either as separate applications or as
a single application. This behavior is
implementation-dependent.
Toolkit-modal type — A toolkit-modal
dialog box blocks all windows that run
in the same toolkit, except windows
from its child hierarchy. If several
applets are launched, all of them run
with the same toolkit. Hence, a
toolkit-modal dialog box shown from an
applet may affect other applets and
all windows of the browser instance
that embeds the Java runtime
environment for this toolkit.
You can define modality while creation:
JDialog dialog = new JDialog(owner, Dialog.ModalityType.DOCUMENT_MODAL);
or later:
dialog.setModalityType(type)
*There is one more level: System Level Modality, but this is not possible with just Java.
Another option is to use a Progress Bar for this.
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.