I am using JOptionPane to show alert box but, it doesn't appear at the top of my current frame. The alert box is getting displayed below all the frames.
Here is the code I am using to show alert box.
JOptionPane.showMessageDialog(null, "Please enter File path", "Error", JOptionPane.WARNING_MESSAGE );
Please let me know how I can make it appear at the top.
"I am using JOptionPane to show alert box but, it doesn't appear at the top of my current frame"
do you mean above, or in front?
if in front (i.e. middle), you have the answer, at least twice, and, if you don't understand,
seriously, consider a career path change.
if, instead, you want to specify where, on the screen, the optionPane is to show,
there is a simple trick that works now, but no guarantees it will work in future versions.
JOptionPane.showMessageDialog(null, "Please enter File path", "Error", JOptionPane.WARNING_MESSAGE );
You can see, that you have written 'null' in the place of the 'parentComponent' (Component),
So, when Rob Prime have written:
from null to a real component
, he meant that You should try to change from null to *"the real" Component*...
I am not sure which is it, becaouse I am learning it now, but it could be a JFrame (a "parent Window"), or a JPanel, or something like this. You should read the "how to..", and javadoc...
But for now, simply replace 'null' with anything that you have in your program (the real component) like JFrame, panel, etc... i don't know, but it's in examples...
[EDIT:]
There are different types of dialogs... That is important. You can read about it in "How to use dialogs", link is above, and in the javadoc.
You can use the frame as the first parameter, or any control (component) you put into that frame. The only difference will be how the dialog will be placed on the screen; it will be centered around the component. If the frame is the first parameter than the dialog will be shown exactly in the center of your frame. If it's a button in your frame it will be centered around the button. In both cases it will block access to the frame.
Post by:autobot
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, that will fit in a stocking