JDK 1.5 Main Window lost after ALT+Tab
When using JDK 1.5.0_05 if I have a main window which is a JFrame which has functionality to display a JDialog, the JDialog is successfully displayed on top of the JFrame.
However if i select another application (via ALT-Tab) and then return to my java application the JDialog is displayed but the JFrame which is the mainframe and which is set as the JDialogs parent is lost in the background. The main window only comes to the top if the JDialog is closed. Is there anyway that when the application is selected than I can get both the JFrame and the JDialog displayed?
Is this a new issue in JDK 1.5. Any ideas?
Kind Regards.
[653 byte] By [
pudliana] at [2007-11-26 17:40:16]

Post a short example, so that we can observe this behavior.
When you create the dialog, make sure you set its parent to the main frame. If you set it to null, the dialog is not modal.~Tim
An example
static JFrame frame;
public static void main(String[] args) {
frame = new JFrame("Sample");
JPanel pnl = new JPanel();
JTextField text = new JTextField();
frame.setBounds(200,200,500,500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
showMessage();
}
private static void showMessage()
{
JOptionPane.showMessageDialog(null, "TEST");
}
That code will have the same behavior you are talking about. However if we change the showMessage() method to this:
private static void showMessage()
{
JOptionPane.showMessageDialog(frame, "TEST");
}
Viola! It does what you want/.
~Tim
A simple example of what I have is:
public class TestFrame extends JFrame
{
public TestFrame()
{
JDialog testDialog = new TestDialog(this);
}
}
class TestDialog extends JDialog
{
public TestDialog(JFrame owner)
{
super(owner);
setLocationRelativeTo(owner);
setModal(true);
setVisible(true);
}
}
When creating the Dialog its parent is set as the mainframe.
> When creating the Dialog its parent is set as the> mainframe.See Reply #1EDIT: for some reason the forum didn't show your second reply. I will take look.
> A simple example of what I have is:
>
> >
> public class TestFrame extends JFrame
> {
>public TestFrame()
> {
>JDialog testDialog = new TestDialog(this);
>
> class TestDialog extends JDialog
> {
>public TestDialog(JFrame owner)
> {
>super(owner);
> setLocationRelativeTo(owner);
>setModal(true);
> setVisible(true);
>}
>
This works fine for me. If I remove the owner from teh super ctor, then it exhibits the behavior you described.
~Tim
Just like SomeoneElse, it appeared to be fine for me as well. However, I had to modify it to have the JFrame appear before the Dialog did. (You didn't have a main method).
Here is what I did:
import javax.swing.JDialog;
import javax.swing.JFrame;
public class TestPad {
public static void main(String[] args) {
new TestFrame();
}
}
class TestFrame extends JFrame {
public TestFrame() {
setVisible(true);
new TestDialog(this);
}
}
class TestDialog extends JDialog {
public TestDialog(JFrame owner) {
super(owner);
setLocationRelativeTo(owner);
setModal(true);
setVisible(true);
}
}