Dialog owner issue with Mac OS X 10.4

C

cpprogrammer

Hi,
I am trying this sample applet on 2 different Mac OS X's

1) Mac OS X 10.3.9
Safari 1.3.2 (v312.6)
JVM - 1.4.2_09

Here whenever the Browser, running the Applet comes on Top, the
Dialog also comes on Top i.e. if the dialog is hidden behind some window
& I click on the browser running the applet, the Dialog(showing "Hello",
"OK")
also becomes uncovered/visible.

2) Mac OS X 10.4.5
Safari 2.0.3 (v417.8)
JVM - 1.4.2_09

Here clicking on the Browser doesn't make the Dialog Visible.

As per the Java Docs, I think the Behaviour on OS X 10.3.9 is the
correct behaviour.

Is there a way to have that behaviour on OS X 10.4 - any workarounds,
anything I can do so that the dialog doesn't get hidden.

I cannot make the dialog modal.

Given below is the Applet source.

------------------------------------------------------------------------

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class MyTest extends Applet implements ActionListener {

private Button b;
private Dialog myDialog;

public void init() {
b = new Button("Press me");
b.addActionListener(this);
add(b);
show();
}

private Frame findFrame(Component c) {
for (; c != null; c = c.getParent()) {
if (c instanceof Frame) return (Frame) c;
}
return null;
}

public void actionPerformed(ActionEvent e) {
if ( e.getSource() == b ) {
showDlg();
}
}

public void showDlg()
{
if(myDialog == null) {
// Set The Applet as owner
Frame f = findFrame(this);
if(f != null) {
System.out.println("Found Frame");
myDialog = new Dialog(f, false);
myDialog.add(new Label("Hello ") , BorderLayout.NORTH);
myDialog.add(new Button("OK"), BorderLayout.SOUTH);
myDialog.pack();
myDialog.show();
}
}
}

}

------------------------------------------------------------------
 
T

Thomas Weidenfeller

cpprogrammer said:
Hi,
I am trying this sample applet on 2 different Mac OS X's

Don't you think cross-posting to four newsgroups because of one problem
is a little bit overdone?
 
C

cpprogrammer

Thomas said:
Don't you think cross-posting to four newsgroups because of one
problem is a little bit overdone?

I am very very tired & sick of getting my App to behave similiarly on
Windows, Mac & Solaris. As of now I would be happy enough if they behave
similiarly even between different versions of the Mac(i.e. 10.3 & 10.4)
running
the same JVM - I am experiencing "Write once, Debug Everywhere" at its
peak.

For Mac Java issues, I originally posted a few questions to the Sun Forum
on the sun website - no replies. Then I posted to the Java forums - no
replies.
Finally, I posted to the Mac Forums, I got a reply which said something
like "this may be why it may be happening, but since I don't know Java, I
can't suggest a fix" - which is when I started crossposting.

Is my question not topical in any of the 4 forums - if so, let me know & I
will
avoid it future.
 
J

Jeffrey Schwab

cpprogrammer said:
I am very very tired & sick of getting my App to behave similiarly on
Windows, Mac & Solaris. As of now I would be happy enough if they behave
similiarly even between different versions of the Mac(i.e. 10.3 & 10.4)
running
the same JVM - I am experiencing "Write once, Debug Everywhere" at its
peak.

For Mac Java issues, I originally posted a few questions to the Sun Forum
on the sun website - no replies. Then I posted to the Java forums - no
replies.
Finally, I posted to the Mac Forums, I got a reply which said something
like "this may be why it may be happening, but since I don't know Java, I
can't suggest a fix" - which is when I started crossposting.

Is my question not topical in any of the 4 forums - if so, let me know & I
will
avoid it future.

Why are you using AWT components instead of Swing? I'm not telling you
what to do, I'm just asking out of curiosity.
 
A

Andrey Kuznetsov

1) Mac OS X 10.3.9
Safari 1.3.2 (v312.6)
JVM - 1.4.2_09

Here whenever the Browser, running the Applet comes on Top, the
Dialog also comes on Top i.e. if the dialog is hidden behind some window
& I click on the browser running the applet, the Dialog(showing "Hello",
"OK")
also becomes uncovered/visible.

2) Mac OS X 10.4.5
Safari 2.0.3 (v417.8)
JVM - 1.4.2_09

Here clicking on the Browser doesn't make the Dialog Visible.

As per the Java Docs, I think the Behaviour on OS X 10.3.9 is the
correct behaviour.

Is there a way to have that behaviour on OS X 10.4 - any workarounds,
anything I can do so that the dialog doesn't get hidden.

I cannot make the dialog modal.

you have to change a bit 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();
}
}
});
System.out.println("Found Frame");
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();
}
}
}

Andrey
 
C

cpprogrammer

Andrey said:
you have to change a bit showDlg():

public void showDlg() {

great. That works in my sample app.
I will try it in my actual program. But
that's surely a start. Tx a lot, Andrey.
 
C

cpprogrammer

cpprogrammer said:
great. That works in my sample app.
I will try it in my actual program. But
that's surely a start. Tx a lot, Andrey.

There is a problem with this fix.

Assume I have a textarea below the button.

i.e.
my init is function is

public void init() {
b = new Button("Press me");
b.addActionListener(this);
TextArea t = new TextArea(1,25);

add(b);
add(t);

show();
}

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.

Also, one other thing I am curious about - why did
your program create an array of size 1,
final Window [] d = new Window[1];

instead of just creating a single object?

i.e. final Window d = null ;
and using it?
 
A

Andrey Kuznetsov

Also, one other thing I am curious about - why did
your program create an array of size 1,
final Window [] d = new Window[1];

instead of just creating a single object?

i.e. final Window d = null ;
and using it?

because you can't change Object declared as final.
my init is function is

public void init() {
b = new Button("Press me");
b.addActionListener(this);
TextArea t = new TextArea(1,25);

add(b);
add(t);

show();
}

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.

Andrey
 
C

cpprogrammer

Andrey said:
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();
}
}
}



}
 
A

Andrey Kuznetsov

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.

<code snipped>

this is strange, because on windows it has expected behavior.
It works also without t.requestFocus();
Since I don't have mac I can't give you another solution.

Andrey
 
S

steve

Hi,
I am trying this sample applet on 2 different Mac OS X's

1) Mac OS X 10.3.9
Safari 1.3.2 (v312.6)
JVM - 1.4.2_09

Here whenever the Browser, running the Applet comes on Top, the
Dialog also comes on Top i.e. if the dialog is hidden behind some window
& I click on the browser running the applet, the Dialog(showing "Hello",
"OK")
also becomes uncovered/visible.

2) Mac OS X 10.4.5
Safari 2.0.3 (v417.8)
JVM - 1.4.2_09

Here clicking on the Browser doesn't make the Dialog Visible.

As per the Java Docs, I think the Behaviour on OS X 10.3.9 is the
correct behaviour.

Is there a way to have that behaviour on OS X 10.4 - any workarounds,
anything I can do so that the dialog doesn't get hidden.

I cannot make the dialog modal.

Given below is the Applet source.

------------------------------------------------------------------------

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class MyTest extends Applet implements ActionListener {

private Button b;
private Dialog myDialog;

public void init() {
b = new Button("Press me");
b.addActionListener(this);
add(b);
show();
}

private Frame findFrame(Component c) {
for (; c != null; c = c.getParent()) {
if (c instanceof Frame) return (Frame) c;
}
return null;
}

public void actionPerformed(ActionEvent e) {
if ( e.getSource() == b ) {
showDlg();
}
}

public void showDlg()
{
if(myDialog == null) {
// Set The Applet as owner
Frame f = findFrame(this);
if(f != null) {
System.out.println("Found Frame");
myDialog = new Dialog(f, false);
myDialog.add(new Label("Hello ") , BorderLayout.NORTH);
myDialog.add(new Button("OK"), BorderLayout.SOUTH);
myDialog.pack();
myDialog.show();
}
}
}

}

I would start by updating the jvm on you machine
currently the version should 1.5
and your os should be 10.4.6
apple have been doing some work on the swing interface
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top