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

Recommended Answers

All 10 Replies

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

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

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Why do I want your jar file?

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

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

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

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.

ok...

.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.