Re: Multiple monitors and JDialog
Rohit Gupta wrote:
....
I am making an Applet in which on a button click a JDialog pops up.
There are two problems which I am facing :
Problem 1 : I have multiple monitors suppose 2 for ex. If the Applet is
running on one and I click the button the JDialog comes up sometimes in
the same monitor and sometimes in the other. I couldnt understand the
factor which governs the position of the JDialog coming up. I have used
setLocationRelativeTo(Applet) function to position my Dialog. I want
the Dialog to be coming up in the same screen. How could I do this?
*
Problem 2 : When the JDialog pops up, the original Applet becomes
unreachable. Now if I open 2/3 other applications on the top, the
Applet goes behind. Now in the taskbar only the applet is visible and
not the Dialog. When I bring the applet on top, I cannot click on it or
do anything because the Dialog isnt closed and the Dialog remains
behind somewhere hidden . I want that in such a situation when I bring
the applet and click on it, the JDialog comes to screen instantly as if
saying "You should Close me before using it" . Can anyone help me out
here?
**
I am not seeing these problems in IE 6 on Win. XP
using Java 1.5 with this code..
<sscce>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DialogApplet
extends JApplet
implements ActionListener {
JDialog d;
public void init() {
JButton b = new JButton("Show Dialog");
b.addActionListener(this);
this.getContentPane().add(b);
}
public void actionPerformed( ActionEvent ie ) {
Frame f = Frame.getFrames()[0];
JLabel label = new JLabel("Hi!");
d = new JDialog(f, true);
d.getContentPane().add(label);
d.pack();
d.setLocationRelativeTo(this);
d.setVisible(true);
}
}
</sscce>
* The dialog appears over the applet (but I have only one monitor)
** I can 'alt tab' to this web-page or select it from the task-bar,
even when it has several windows on top of it and the dialog is open.
(N.B. It assumes the name of the dialog title)
Does this code work as you'd expect it to?
If not, what is your browser/Java/OS?
Andrew T.