joktur
asked on
Locate window dialog
I'm opening a window dialog from an applet and, by default, it is located in the top-left of screen coordinates.
Actually I can locate this window with super.setLocation(X,Y), but I'd prefer to relate it with the main window position.
How ca I get that position? (parent.getLocation() doesn't work!)
Actually I can locate this window with super.setLocation(X,Y), but I'd prefer to relate it with the main window position.
How ca I get that position? (parent.getLocation() doesn't work!)
and yourDialog.getLocationOnSc reen()
Is not necesary to make calls to parent since those methods are public and inherited by your dialog, especialy if the parent is null.
ASKER
I'm looking for a location to set my dialog. For this I'll consider the main window position, where is the applet.
i.e, I know dialog's location (yourDialog.getLocation(); ) but I'm looking for parent's dialog position.
Thks
i.e, I know dialog's location (yourDialog.getLocation();
Thks
and who is the parent dialog? the browser window?
ASKER
I'm looking for a location to set my dialog. For this I'll consider the main window position, where is the applet.
i.e, I know dialog's location (yourDialog.getLocation(); ) but I'm looking for parent's dialog position.
Thks
i.e, I know dialog's location (yourDialog.getLocation();
Thks
ASKER
yes. It's where dialog comes.
try this
public class window ....
{
...
public set_Location(int x,int y)
{
this.setLocation(x,y);
}
}
public class my_applet ...
{
...
window.set_Location((int)t his.getLoc ation().ge tX(),(int) this.getLo cation().g etY());
}
public class window ....
{
...
public set_Location(int x,int y)
{
this.setLocation(x,y);
}
}
public class my_applet ...
{
...
window.set_Location((int)t
}
ASKER
yes. It's where dialog comes.
use yourApplet.getLocation() or yourApplet.getLocationOnSc reen()
ASKER
yes. It's where dialog comes.
Yes loukas the great is write!
perfect solution!
Elladara!!!
perfect solution!
Elladara!!!
like I've said before, use yourApplet.getLocation() or yourApplet.getLocationOnSc reen() to determine the applet location, and compute accordingly the desired location of the window.
ASKER
yes. It's where dialog comes.
ASKER
It looks easy and logic but doesn't work.
Here's the sequence:
public mainClass extends Applet{
...
myClassDialog d= new myClassDialog(this);
d.show();
}
class myClassDialog extends Dialog{
myClassDialog(mainClass p);
//Now i'd like to locate this dialog related to p
//1: absolute location
this.setLocation(500,500); //it works
//2: relative location
this.setLocation(p.getLoca tion().get X(),p.getL ocation(). getY()); //dialog doesn't open
}
Here's the sequence:
public mainClass extends Applet{
...
myClassDialog d= new myClassDialog(this);
d.show();
}
class myClassDialog extends Dialog{
myClassDialog(mainClass p);
//Now i'd like to locate this dialog related to p
//1: absolute location
this.setLocation(500,500);
//2: relative location
this.setLocation(p.getLoca
}
have you tried with getLoationOnScreen()?
ASKER
It looks easy and logic but doesn't work.
Here's the sequence:
public mainClass extends Applet{
...
myClassDialog d= new myClassDialog(this);
d.show();
}
class myClassDialog extends Dialog{
myClassDialog(mainClass p);
//Now i'd like to locate this dialog related to p
//1: absolute location
this.setLocation(500,500); //it works
//2: relative location
this.setLocation(p.getLoca tion().get X(),p.getL ocation(). getY()); //dialog doesn't open
}
Here's the sequence:
public mainClass extends Applet{
...
myClassDialog d= new myClassDialog(this);
d.show();
}
class myClassDialog extends Dialog{
myClassDialog(mainClass p);
//Now i'd like to locate this dialog related to p
//1: absolute location
this.setLocation(500,500);
//2: relative location
this.setLocation(p.getLoca
}
ASKER
It looks easy and logic but doesn't work.
Here's the sequence:
public mainClass extends Applet{
...
myClassDialog d= new myClassDialog(this);
d.show();
}
class myClassDialog extends Dialog{
myClassDialog(mainClass p);
//Now i'd like to locate this dialog related to p
//1: absolute location
this.setLocation(500,500); //it works
//2: relative location
this.setLocation(p.getLoca tion().get X(),p.getL ocation(). getY()); //dialog doesn't open
}
Here's the sequence:
public mainClass extends Applet{
...
myClassDialog d= new myClassDialog(this);
d.show();
}
class myClassDialog extends Dialog{
myClassDialog(mainClass p);
//Now i'd like to locate this dialog related to p
//1: absolute location
this.setLocation(500,500);
//2: relative location
this.setLocation(p.getLoca
}
ASKER
> have you tried with getLoationOnScreen()?
yes. Doesn't work.
yes. Doesn't work.
I must leave now. If you don't have a solution until tomorrow, I will try to help you.
ASKER
> have you tried with getLoationOnScreen()?
yes. Doesn't work.
yes. Doesn't work.
ASKER
> have you tried with getLoationOnScreen()?
yes. Doesn't work.
yes. Doesn't work.
There is no way to determine the location of the browser window that I know of.
Sorry, but my applet works fine and opens a MODAL dialog relatively to the position of the applet on the screen. The dialog behaves like a native modal dialog, in the sense that you cannot click nothing until you close'it. Tested in IE and Mozilla.
/*
* Created on Apr 2, 2003
*
* To change this generated comment go to
* Window>Preferences>Java>Co de Generation>Code Template
*/
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListe ner;
import java.awt.event.WindowAdapt er;
import java.awt.event.WindowEvent ;
/**
* @author ovi
*/
public class AppletLocation extends Applet {
private Button open = new Button("Open");
public void init() {
setLayout(new BorderLayout());
add(open, BorderLayout.SOUTH);
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEven t arg0) {
openDialog();
}
});
}
private void openDialog() {
Container c = this;
while (c != null && !(c instanceof Frame)) {
c = c.getParent();
}
if (c == null)
c = new Frame();
Frame parent = (Frame) c;
int w = 150;
int h = 150;
int x = parent.getLocationOnScreen ().x;
int y = parent.getLocationOnScreen ().y;
final Dialog dlg = new Dialog(parent, "Test", true);
dlg.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
dlg.setVisible(false);
dlg.dispose();
}
});
dlg.setSize(w, h);
dlg.setLocation(x - 20, y - 20);
dlg.setVisible(true);
System.out.println("Should not get here when dlg is visible");
}
}
/*
* Created on Apr 2, 2003
*
* To change this generated comment go to
* Window>Preferences>Java>Co
*/
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.event.ActionEvent
import java.awt.event.ActionListe
import java.awt.event.WindowAdapt
import java.awt.event.WindowEvent
/**
* @author ovi
*/
public class AppletLocation extends Applet {
private Button open = new Button("Open");
public void init() {
setLayout(new BorderLayout());
add(open, BorderLayout.SOUTH);
open.addActionListener(new
public void actionPerformed(ActionEven
openDialog();
}
});
}
private void openDialog() {
Container c = this;
while (c != null && !(c instanceof Frame)) {
c = c.getParent();
}
if (c == null)
c = new Frame();
Frame parent = (Frame) c;
int w = 150;
int h = 150;
int x = parent.getLocationOnScreen
int y = parent.getLocationOnScreen
final Dialog dlg = new Dialog(parent, "Test", true);
dlg.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
dlg.setVisible(false);
dlg.dispose();
}
});
dlg.setSize(w, h);
dlg.setLocation(x - 20, y - 20);
dlg.setVisible(true);
System.out.println("Should
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help.
I'll implement a thread to accept inputs from js. It's easy and works.
Best regards
I'll implement a thread to accept inputs from js. It's easy and works.
Best regards
mee too. The applet onscreen location is not enough for you?
ASKER
yes, it's enough.
I believe there is no thread necesary, since you need those coordinates only when you make the dialog visible.
ASKER
yes, it's enough.
ASKER
yes, it's enough.
ASKER
That's right, I can it on fly.
This is a personal project to public my own java/GIS develops. You can look it through
http://www.portugalturismo.net > (pt only, sorry) MAPAS > e.g. Portugal > <Find icon>
30k Java1 based
This is a personal project to public my own java/GIS develops. You can look it through
http://www.portugalturismo.net > (pt only, sorry) MAPAS > e.g. Portugal > <Find icon>
30k Java1 based
That's realy nice!
I have some suggestions:
1. You should implement a little doublebuffering to avoid flickering of the applet.
2. Put all classes in a jar file, it will load more quickly. Right now I have a very poor connection.
3. When you move around the map would be interesting if I can press and hold a arrow and the image will move herself, and not by many clicks.
:-) hope do't get me wrong, this are just few opinions. But there is a nice applet.
I have some suggestions:
1. You should implement a little doublebuffering to avoid flickering of the applet.
2. Put all classes in a jar file, it will load more quickly. Right now I have a very poor connection.
3. When you move around the map would be interesting if I can press and hold a arrow and the image will move herself, and not by many clicks.
:-) hope do't get me wrong, this are just few opinions. But there is a nice applet.
ASKER
Thks for your suggestions.
1. (doublebuffering) I've done it creating an image, but it becames the re-rendering slow.
2. (jar) ok
3. (pan) easy with buffers
Have you seen the Dialog?
1. (doublebuffering) I've done it creating an image, but it becames the re-rendering slow.
2. (jar) ok
3. (pan) easy with buffers
Have you seen the Dialog?
no
ASKER
The 8th tool button from the left aims to open it.
I see'it now, but you are not using the applet coordinates yet :).
A more direct connection with me : ovi@sec.co.ro
A more direct connection with me : ovi@sec.co.ro
you should use yourDialog.getLocation();