Link to home
Start Free TrialLog in
Avatar of joktur
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!)
Avatar of Ovi
Ovi

why parent.getLocation()?
you should use yourDialog.getLocation();
and yourDialog.getLocationOnScreen()
Is not necesary to make calls to parent since those methods are public and inherited by your dialog, especialy if the parent is null.
Avatar of joktur

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
and who is the parent dialog? the browser window?
Avatar of joktur

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
Avatar of joktur

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)this.getLocation().getX(),(int)this.getLocation().getY());
}
Avatar of joktur

ASKER

yes. It's where dialog comes.
use yourApplet.getLocation() or yourApplet.getLocationOnScreen()
Avatar of joktur

ASKER

yes. It's where dialog comes.
Yes loukas the great is write!

perfect solution!

Elladara!!!
like I've said before, use yourApplet.getLocation() or yourApplet.getLocationOnScreen() to determine the applet location, and compute accordingly the desired location of the window.
Avatar of joktur

ASKER

yes. It's where dialog comes.
Avatar of joktur

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.getLocation().getX(),p.getLocation().getY()); //dialog doesn't open
 

}
have you tried with getLoationOnScreen()?
Avatar of joktur

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.getLocation().getX(),p.getLocation().getY()); //dialog doesn't open
 

}
Avatar of joktur

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.getLocation().getX(),p.getLocation().getY()); //dialog doesn't open
 

}
Avatar of joktur

ASKER

> have you tried with getLoationOnScreen()?
yes. Doesn't work.
I must leave now. If you don't have a solution until tomorrow, I will try to help you.
Avatar of joktur

ASKER

> have you tried with getLoationOnScreen()?
yes. Doesn't work.
Avatar of joktur

ASKER

> have you tried with getLoationOnScreen()?
yes. Doesn't work.
Avatar of Mick Barry
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>Code 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.ActionListener;
import java.awt.event.WindowAdapter;
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(ActionEvent 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");
     }
}
ASKER CERTIFIED SOLUTION
Avatar of Ovi
Ovi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joktur

ASKER

Thanks for your help.
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?
Avatar of joktur

ASKER

yes, it's enough.
I believe there is no thread necesary, since you need those coordinates only when you make the dialog visible.
Avatar of joktur

ASKER

yes, it's enough.
Avatar of joktur

ASKER

yes, it's enough.
Avatar of joktur

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
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.
Avatar of joktur

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?
no
Avatar of joktur

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