0

When i clicked on JMenuitem ..it opens a new window ..but when i close this window the parent window also closes...

is there any method to resolve ..i don't want to close the parent window only the new window..

2
Contributors
10
Replies
11
Views
7 Years
Discussion Span
Last Post by amit.hak50
0

Post a small working program to show what you are talking about.

Edited by NormR1: n/a

0
import javax.swing.*;
import java.awt.*;

import com.sun.awt.AWTUtilities;

import java.awt.Color;
import java.awt.Point;
import java.awt.Shape;
import java.awt.event.*;
import java.awt.geom.RoundRectangle2D;

public class window extends JFrame{

    public static void main(String args[])
    {


    JFrame window=new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    window.setSize(400,500);
    window.setVisible(true);


    //Container c= window.getContentPane();

    JMenuBar menubar=new JMenuBar();

    window.setJMenuBar(menubar);
    JMenu help=new JMenu("help");
    menubar.add(help);
    JMenuItem helpcontent=new JMenuItem("helpcontent");
    help.add(helpcontent);
helpcontent.addActionListener(new ActionListener()
{
    public void actionPerformed(ActionEvent e)
    {
        JTextArea ta = new JTextArea(10, 35);
        JScrollPane jscrollpane = new JScrollPane(ta);

          JFrame f = new JFrame("JScrollPane");
          f.setUndecorated(false);
          f.setLocation(new Point(700, 182));
          f.getContentPane().add(jscrollpane);
          f.setBackground(Color.gray);



          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.setSize(250, 300);
          f.setVisible(true);
    }
});




    }




}

This is the small working program...when you click on helpcontent .it opens a window and when you close it closes the main(parent ) window also ....I do not want the parent window to close ..i want only to close the opening window..

If you can help it would be great....

Edited by mike_2000_17: Fixed formatting

0

just to run it...by double click my dude...by this way ..you can run it ...my code ..you will be able to see the example by double click ...

0

Did you look at the code I posted earlier? Read the API doc for that method and its args.

0

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

but it closes both window ...I don't want that to close ..it also closes parent window...only the second window needs to be closed not the parent one ..look at the code above ...i did that

0

Did you read the API doc for the method call that I posted above?
Please do. Then come back if you have any questions.
Be sure to copy and paste here the text of the doc you question.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.