aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Opening a frame from a dialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Opening a frame from a dialog" Watch "Opening a frame from a dialog" New topic
Author

Opening a frame from a dialog

Mihalache Catalin
Greenhorn

Joined: Sep 01, 2003
Posts: 7
Hello to all,
From a very specific reason I need to open a JFrame from a JDialog.
I think that is impossible.
Maybe somebody bad the same problem and can help me with some tips.
Thaks,
Cata
Jan Michael Soan
Ranch Hand

Joined: Feb 08, 2003
Posts: 36
You can call JFrame by using a package declaration if you have 2 separate .java files and you want to connect them it doesnt matter if they are JFrame or JDailog as long as they are separate just call the 2nd one to the 1st one using package.
like :
package soan.jan.michael;
import soan.jan.michael.The Frame;
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Welcome to JavaRanch!
You can create a JFrame from any code (including JDialog code) just by using its constructor.
JFrame frame = new JFrame("Window Title");
I'm sure, though, that your problem is a bit more specific, or you wouldn't have posted this question; can you give us some more details about the difficulty you're having?


[Jess in Action][AskingGoodQuestions]
Mihalache Catalin
Greenhorn

Joined: Sep 01, 2003
Posts: 7
Thanks for your responses,
My problem is:
I have a JDialog with some data. When I push a button in this dialog (an "edit" button) I need to open a JFrame with some details for editing.
I want this JFrame to be on top of the parent JDialog; I don't want to close the original JDialog; I just want JDialog to be parent for a JFrame.
I tried: I can open that JFrame but it always loose the focus.
Thanks,
Cata
Jan Michael Soan
Ranch Hand

Joined: Feb 08, 2003
Posts: 36
Can you produce your codes so that we can help U ?, thanks !@.
Mihalache Catalin
Greenhorn

Joined: Sep 01, 2003
Posts: 7
This is the problematic code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class myDialog extends JDialog {
/** Creates a new instance of myDialog */
public myDialog(){
setModal(true);
setTitle("Some data into a dialog window");
getContentPane().setLayout(null);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
JButton btnOpenJFrame = new JButton("Open a JFrame()");
btnOpenJFrame.setSize(300, 25);
getContentPane().add(btnOpenJFrame);
btnOpenJFrame.setLocation(30, 30);

pack();
setLocation(10, 10);
setSize(400, 300);
setResizable(false);

addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
myDialog.this.dispose();
System.exit(0);
}
}
);

btnOpenJFrame.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame myJFrame = new JFrame(
"Here I perform some edit operations");
myJFrame.setDefaultCloseOperation(
JFrame.DISPOSE_ON_CLOSE);
myJFrame.setSize(600, 500);
myJFrame.setLocation(10, 10);
myJFrame.show();
myJFrame.requestFocus();
}
}
);

}

/** Main entry point */
public static void main(String args[]){
new myDialog().show();
}

}
 
 
subject: Opening a frame from a dialog