I have two JFrames
(mainFrame.java & child.java) designed in NetBeans editor. I want to call second JFrame
from the first frame as a child window. How can I call it?
Asked
Active
Viewed 3,767 times
2

mKorbel
- 109,525
- 20
- 134
- 319

Pankaj Kumar Thapa
- 131
- 1
- 2
- 6
-
I want to call child.java after clicking a button in mainFrame.java @LewsTherin . – Pankaj Kumar Thapa Sep 26 '12 at 05:26
3 Answers
2
don't use two JFrames, the best suggestion why not, or e.i. is answer by
@Andrew Thompson
have look at JDialog
to check JDialog(Dialog owner, boolean modal) or ModalityTypes
0
Make the object of the first frame and then call it in the second frame.
firstframe fm = new firstframe();
fm.setVisible(true);

Chathuranga Chandrasekara
- 20,548
- 30
- 97
- 138

Pavas Srivastava
- 1
- 1
0
If I understand correctly you would like to have a main Window with child/children window inside of it. If this is so, check out the below code.
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/**
* Sample demonstrates using JInternalFrame as a child window of a main
* JFrame window TicTacToe class extends JInternalFrame.
* @author Kirk
*
*/
public class BoardBuilder extends JFrame {
private TicTacToe board;
JDesktopPane desktopPane = new JDesktopPane();
public BoardBuilder() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
board = new TicTacToe("TicToc Toe", true);
board.setSize(250, 250);
board.setClosable(true);
board.setIconifiable(true);
board.setDefaultCloseOperation(TicTacToe.DISPOSE_ON_CLOSE);
if (!board.isVisible())
board.setVisible(true);
desktopPane.add(board);
add(desktopPane);
}
});
}
public static void main(String[] args) {
BoardBuilder builderBoard = new BoardBuilder();
builderBoard.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
builderBoard.setSize(640, 480);
builderBoard.setVisible(true);
}
}
to call the child window place this code block in a button Click event Listener
SwingUtilities.invokeLater(new Runnable() {
public void run() {
board = new TicTacToe("TicToc Toe", true);
board.setSize(250, 250);
board.setClosable(true);
board.setIconifiable(true);
board.setDefaultCloseOperation(TicTacToe.DISPOSE_ON_CLOSE);
if (!board.isVisible())
board.setVisible(true);
desktopPane.add(board);
add(desktopPane);
}
});
For future info check out this link docs.oracle-InternalFrames

Kirk Patrick Brown
- 174
- 1
- 7