This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Opening a frame from a dialog

 
Mihalache Catalin
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mihalache Catalin
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you produce your codes so that we can help U ?, thanks !@.
 
Mihalache Catalin
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic