• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change the first parameter from null to a real component; one inside the frame you want to block (or the frame itself).
 
Rite Sara
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't get your reply ..
Could you please elaborate in more details ??
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rite Sara wrote:Could you please elaborate in more details

Read the code you posted in your first post.
 
Rite Sara
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to replace null with

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


 
Rite Sara
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's exactly what I am not getting .. Please elaborate on this ..
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,...




 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic