Forums Register Login

How to display alert box at the top of all frames ?

+Pie Number of slices to send: Send
Hi,

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.


Thanks,

+Pie Number of slices to send: Send
Change the first parameter from null to a real component; one inside the frame you want to block (or the frame itself).
+Pie Number of slices to send: Send
I didn't get your reply ..
Could you please elaborate in more details ??
+Pie Number of slices to send: Send
 

Rite Sara wrote:Could you please elaborate in more details

Read the code you posted in your first post.
+Pie Number of slices to send: Send
Actually the part I didnt understand was

a real component; one inside the frame you want to block (or the frame itself).



I didn't get what exactly I have to replace null with.
+Pie Number of slices to send: Send
You have to replace null with

a real component; one inside the frame you want to block (or the frame itself).


+Pie Number of slices to send: Send
That's exactly what I am not getting .. Please elaborate on this ..
+Pie Number of slices to send: Send
> Please elaborate on this ..

you first.

"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.
+Pie Number of slices to send: Send
I'll try...

the parameters of the method look like this:

public static void showMessageDialog(Component parentComponent,
Object message,
String title,
int messageType)
throws HeadlessException

Parameters:

parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used

message - the Object to display

title - the title string for the dialog

messageType - the type of message to be displayed: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE

icon - an icon to display in the dialog that helps the user identify the kind of message that is being displayed




I quoted this from JavaDocs.. Like for example, from here:
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JOptionPane.html


And this is also what you would need:
http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/components/dialog.html


So, when You writted it, it was like:


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.

[EDIT2:]
Actually,...




+Pie Number of slices to send: Send
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.
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 9586 times.
Similar Threads
javascript form validation
How to set the field value of type "File" dynamically in JavaScript?
How to show alert box when database connection is successful
jsp forwarding to a target frame
value undefined....how to remove that?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:55:08.