AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Positioning dialogboxes created with JOptionPane

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
Sameer
Guest





PostPosted: Sun Sep 18, 2005 4:05 pm    Post subject: Positioning dialogboxes created with JOptionPane Reply with quote



The dialog boxes created using JOptionPane like showConfirmDialog,
showInputDialog gets displayed in the centre of the screen. I need to change
its position. How to do this?
These methods return int or none.
How to get access to the dialog boxes so that they
can be positioned by using appropriate method? or I need to create a custom
dialog box so that they can be positioned?




Back to top
Roedy Green
Guest





PostPosted: Sun Sep 18, 2005 5:57 pm    Post subject: Re: Positioning dialogboxes created with JOptionPane Reply with quote



On Sun, 18 Sep 2005 21:35:24 +0530, "Sameer"
<spamtoobad-sameer (AT) yahoo (DOT) com> wrote or quoted :

Quote:
The dialog boxes created using JOptionPane like showConfirmDialog,
showInputDialog gets displayed in the centre of the screen. I need to change
its position. How to do this?
These methods return int or none.
How to get access to the dialog boxes so that they
can be positioned by using appropriate method? or I need to create a custom
dialog box so that they can be positioned?

JOptionPane inherits from JComponent, hence it has the usual
setLocation, setX and setY methods. What happens when you try those?
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Back to top
Sameer
Guest





PostPosted: Sun Sep 18, 2005 7:46 pm    Post subject: Re: Positioning dialogboxes created with JOptionPane Reply with quote



Consider some methods of JOptionPane:
1) static int showConfirmDialog(Component parentComponent, Object
message, String title, int optionType, int messageType, Icon icon)

2) static String showInputDialog(Component parentComponent, Object
message)

These are the methods which return int and String respectively.
If static methods doing the work to show dialog box, then how do i get
instance of JOptionPane to operate on i.e. to apply the method
setLocation etc.-

Please explain with the help of a code-snippet.

Back to top
Roedy Green
Guest





PostPosted: Sun Sep 18, 2005 9:48 pm    Post subject: Re: Positioning dialogboxes created with JOptionPane Reply with quote

On 18 Sep 2005 12:46:31 -0700, "Sameer" <spamtoobad-sameer (AT) yahoo (DOT) com>
wrote or quoted :

Quote:
Please explain with the help of a code-snippet.

Try setLocation on the JOptionPane to humour me. It is possible it
propagates that information to Windows it pops up in a way similar to
the way other nested components do.

Another approach to the problem is to too study the code for
JOptionPane to see how it determines where to pop up. That may give
you an hint as to how you might influence it.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Back to top
Thomas Fritsch
Guest





PostPosted: Sun Sep 18, 2005 9:54 pm    Post subject: Re: Positioning dialogboxes created with JOptionPane Reply with quote

"Sameer" <spamtoobad-sameer (AT) yahoo (DOT) com> wrote:
Quote:
The dialog boxes created using JOptionPane like showConfirmDialog,
showInputDialog gets displayed in the centre of the screen. I need to
change
its position. How to do this?
All the static JOptionPane.show???Dialog methods take a

Component parentComponent
as their first parameter. The created dialog will be centered relative to
that parentComponent.
So it is important to to give a suitable component there, like
JOptionPane.show???Dialog(component, ...);
or better
JOptionPane.show???Dialog(JOptionPane.getFrameForComponent(component),
....);
It seems that you gave null as parentComponent, because then the dialog will
be centered in the screen.

Quote:
These methods return int or none.
How to get access to the dialog boxes so that they
can be positioned by using appropriate method? or I need to create a
custom
dialog box so that they can be positioned?

--
"TFritsch$t-online:de".replace(':','.').replace('$','@')



Back to top
Sameer
Guest





PostPosted: Mon Sep 19, 2005 9:34 am    Post subject: Re: Positioning dialogboxes created with JOptionPane Reply with quote

The dialog box generated is a part of error-handling code and must be
executed to validate command line parameters.
Upto validation point there is no necessary to display GUI, so there is
no parent component to any of the dialog boxes so I have to pass null
as the parameter.

Back to top
Thomas Fritsch
Guest





PostPosted: Mon Sep 19, 2005 11:08 am    Post subject: Re: Positioning dialogboxes created with JOptionPane Reply with quote

Sameer schrieb:

Quote:
Consider some methods of JOptionPane:
1) static int showConfirmDialog(Component parentComponent, Object
message, String title, int optionType, int messageType, Icon icon)

2) static String showInputDialog(Component parentComponent, Object
message)

These are the methods which return int and String respectively.
If static methods doing the work to show dialog box, then how do i get
instance of JOptionPane to operate on i.e. to apply the method
setLocation etc.-

Please explain with the help of a code-snippet.

So, if the static JOptionPane-methods don't fit, use a constructor and

the non-static methods:
JOptionPane optionPane = new JOptionPane("message");
JDialog dialog = optionPane.createDialog(null, "title");
dialog.setLocation(100, 100);
dialog.setVisible(true);
Object value = optionPane.getValue();
int option;
if (value == null)
option = JOptionPane.CLOSED_OPTION;
else
option = ((Integer) value).intValue();

BTW: reading the javadoc of JOptionPane always helps.

--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')


Back to top
Roedy Green
Guest





PostPosted: Tue Sep 20, 2005 6:58 am    Post subject: Re: Positioning dialogboxes created with JOptionPane Reply with quote

On 19 Sep 2005 02:34:24 -0700, "Sameer" <spamtoobad-sameer (AT) yahoo (DOT) com>
wrote or quoted :

Quote:
The dialog box generated is a part of error-handling code and must be
executed to validate command line parameters.
Upto validation point there is no necessary to display GUI, so there is
no parent component to any of the dialog boxes so I have to pass null
as the parameter.

A pragmatic person might say -- ok, pop up a parent, position the
parent then the child has to fit inside.

I will give my original answer for the third time. Try using the
setLocation methods on your JOptionPane. It IS a JComponent after all,
and that is how you position JComponents.


--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Back to top
E11
Guest





PostPosted: Tue Sep 20, 2005 3:59 pm    Post subject: Re: Positioning dialogboxes created with JOptionPane Reply with quote

Roedy,

The setLocation in JOptionPane (or rather, Component, but inherited by
JOptionPane) is non-static. i.e. If you have an object instance of
JOptionPane, then you can call object.setLocation(...).

When you use the convenience static methods
JOptionPane.showConfirmDialog(...), they do not return you the handle
to the dialog box that is shown. Rather it only returns you the value
representing the user-input.

Sameer, if you have no other frame or dialog to centre the dialog box
against, i would suggest that you create a custom dialog class that
extends the JDialog. You can even make use of parameters and static
convenience methods to make it configurable, and work just like
JOptionPane.showConfirmDialog(...).



Regards,
Edwin

Back to top
Sameer
Guest





PostPosted: Thu Sep 22, 2005 8:31 pm    Post subject: Re: Positioning dialogboxes created with JOptionPane Reply with quote

Thanks!
At last the class which helped me to locate the dialog box
appropriately is:


import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

public class ErrorDialog {
String message;
String title;
int splashImageHeight;
int distanceFromSplashWindow;

public ErrorDialog(String title, String message, int splashHeight, int
distanceBetween) {
super();
distanceFromSplashWindow = distanceBetween;
this.message = message;
splashImageHeight = splashHeight;
this.title = title;

JOptionPane jop = new JOptionPane(message);
JDialog jdg = jop.createDialog(null, title);
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screenDim = tk.getScreenSize();
int errW = screenDim.width / 2 - jdg.getWidth() / 2;
int errH = screenDim.height / 2 + splashImageHeight / 2+
distanceFromSplashWindow;
jdg.setLocation(errW, errH);
jdg.setVisible(true);
}

}

May be helpful to anybody.
Thanks again for posting for this thread.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.