Re: Dialog owner issue with Mac OS X 10.4
Andrey Kuznetsov wrote:
Now once the dialog has been activated it always
has input focus - I can never type text into the
textarea - i.e. the dialog behaves like a modal dialog.
Your init function is ok.
You probably changed something else.
Post your complete code.
Here is my complete code.
Now the dialog is always on front when the browser
is in front. However, I can never type anything into
the textarea.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class MyTest extends Applet implements ActionListener{
private Button b;
private Dialog myDialog;
private TextArea t;
public void init() {
b = new Button("Press me");
b.addActionListener(this);
t = new TextArea(1,25);
add(b);
add(t);
show();
}
private Frame findFrame(Component c) {
for (; c != null; c = c.getParent()) {
if (c instanceof Frame) {
return (Frame) c;
}
}
return null;
}
public void RF()
{t.requestFocus();}
public void actionPerformed(ActionEvent e) {
if ( e.getSource() == b ) {
showDlg();
}
}
public void showDlg() {
if (myDialog == null) {
// Set The Applet as owner
final Frame f = findFrame(this);
final Window [] d = new Window[1];
if (f != null) {
f.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {
if(d[0] == null || d[0] != f) {
myDialog.toFront();
RF();
}
}
});
myDialog = new Dialog(f, false);
myDialog.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {
d[0] = e.getOppositeWindow();
}
public void windowDeactivated(WindowEvent e) {
d[0] = e.getOppositeWindow();
}
});
myDialog.add(new Label("Hello "), BorderLayout.NORTH);
myDialog.add(new Button("OK"), BorderLayout.SOUTH);
myDialog.pack();
myDialog.show();
}
}
}
}