File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Opening a frame from a dialog" Watch "Opening a frame from a dialog" New topic

Opening a frame from a dialog

Mihalache Catalin

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.
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

Joined: Jul 08, 2003
Posts: 24199

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

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.
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

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(){
setTitle("Some data into a dialog window");
JButton btnOpenJFrame = new JButton("Open a JFrame()");
btnOpenJFrame.setSize(300, 25);
btnOpenJFrame.setLocation(30, 30);

setLocation(10, 10);
setSize(400, 300);

new WindowAdapter(){
public void windowClosing(WindowEvent e){

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


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

I agree. Here's the link:
subject: Opening a frame from a dialog
It's not a secret anymore!