• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1020
  • Last Modified:

how to show JInternalFrame

how can i show my internal frame when i click the menu item.
can you fix the code


public class test extends javax.swing.JFrame {
   
    /** Creates new form test */
    public test() {
        initComponents();
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
        intframeTest = new javax.swing.JInternalFrame();
        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        intframeTest.setClosable(true);
        intframeTest.setIconifiable(true);
        intframeTest.setMaximizable(true);
        intframeTest.setResizable(true);
        getContentPane().add(intframeTest, java.awt.BorderLayout.CENTER);

        jMenu2.setText("Menu");
        jMenuItem2.setText("test");
        jMenu2.add(jMenuItem2);

        jMenuBar2.add(jMenu2);

        setJMenuBar(jMenuBar2);

        pack();
    }

    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
    public static void main(String args[]) {
        new test().show();
    }
   
    // Variables declaration - do not modify
    private javax.swing.JInternalFrame intframeTest;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem jMenuItem2;
    // End of variables declaration
   
}

0
orhanbaba
Asked:
orhanbaba
  • 3
1 Solution
 
TimYatesCommented:
You add internal frames to a JDeskTop component...
0
 
TimYatesCommented:
What are you trying to do?  I think you need to have a rethink about how your UI is going to look as you seem to be adding an Internal Frame to a Frame, with the menus on the Internal Frame, and on the Frame as well...

Also, Internal Frames can't be Modal (unless you do some proper hacking -- none of which works 100% believe me I've tried)...

Tim
0
 
suprapto45Commented:
0
 
TimYatesCommented:
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;

public class Test extends javax.swing.JFrame {

    public Test() {
        initComponents();
    }

    private void initComponents() {
        intframeTest = new javax.swing.JInternalFrame( "Testing" );
        intframeTest.getContentPane().add( new JButton( "Blah" ) ) ;
        intframeTest.pack();

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        intframeTest.setClosable(true);
        intframeTest.setIconifiable(true);
        intframeTest.setMaximizable(true);
        intframeTest.setResizable(true);
        jMenu1.setText("Menu");
        jMenuItem1.setText("test");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });

        desktop = new JDesktopPane() ;
        this.setContentPane( desktop ) ;
        this.setJMenuBar( jMenuBar1 );
        jMenu1.add(jMenuItem1);
        jMenuBar1.add(jMenu1);

//        intframeTest.setJMenuBar(jMenuBar1);
        setSize( 300, 300 ) ;
        setLocationRelativeTo( null ) ;
    }

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
        // what will i write here to show my internal frame
        System.out.println( "Woo" ) ;
        intframeTest.setVisible( true );
        intframeTest.setLocation( 10, 10 );
        desktop.add( intframeTest ) ;
    }

    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
    public static void main(String args[]) {
        new Test().show();
    }

    // Variables declaration - do not modify
    private javax.swing.JInternalFrame intframeTest;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JDesktopPane desktop ;
    // End of variables declaration

}
0
 
orhanbabaAuthor Commented:
i solved it manually but thank you Tim
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now