Closing an JInternalFrame

hey guys, when i click on a JMenuItem close, i want the active JInternalFrame to close, how can i achieve this? and when i click on JMenuItem close all i want all open JInternalFrames to close,
thanx

the code below is what iam using to close the windows
//close button
returnItem1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
desktop.getSelectedFrame().setClosed(true);
     } catch (java.beans.PropertyVetoException pve) {}
//close all button
returnItem2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JInternalFrame Frames[] = desktop.getAllFrames(); // get all open frames
     for(int FrameLoop=0; FrameLoop < Frames.length; FrameLoop++)
     try
     Frames[FrameLoop].setClosed(true); // close the frame
     catch (Exception CloseExc)
     // if we can't close it then we have a problem
     JOptionPane.showMessageDialog(null, CloseExc);
thanx for having a look at my code

Similar Messages

  • How to renable a closed Internal frame?

    Hi Friends,
    I got few intenal frames which can be closed at any point. I dont loose the Jinternalframe Object though. Can I again show the internal frame even if some closes the the internal frame window. Please let me know how ? I will be glad.
    Regards,
    Ravi.

    rather than actually closing the JInternalFrames, use setVisible(false) on a frame to hide it from the user. If you want to bring the window back simply call setVisible(true) on the frame you want to reinstate. You can override the default window closing behaviour to do this fairly easily.

  • YourKit Java Profiler 6.0.16

    Hi here is my problem, I am using the YourKit Java Profiler.
    everytime time I am closing a JInternalFrame what I noticed in this YourKit Profiler is that Allocated Memory is not decreasing when I dispose() the JInternalFrame. What do I need to do so when I dispose() this JInternalFrame the Allocated Memory is free up.
    Allocated Memory is only increasing.
    Please I need big help on this one.
    Wilfer

    We have been running 1.6 update 12 without any problems.  We have only encountered problems when we recently updated to update 16. 
    For security purposes we are unable to use 1.5 because of some security flaw.

  • JInternalFrame is closed, but does not release the memory

    Hi,
    I have problem with using of JInternalFrame.
    I create a new internal frame, and close it."setClosed(true);dispose();"
    The frame does not release the memory (after gc the allocated memory is the same)
    Before close I removed all listeners, and closed all reference to other object. (I think so :-) )
    Do You have any idees?
    regards
    G�bor

    Hi,
    I think u will have to release all the associated used objects. or you can also call the finalize() method in order to release the memory.
    Regards,
    Balaji.SN

  • Problem closing JInternalFrame without first activating it

    Hi all,
    In my app when user clicks a button in JInternalFrame A, JInternalFrame B pops up, so I want to close JInternalFrame B when user close JInternalFrame A.
    I put the routine in JInternalFrame A's closing event. Everything works fine if the user click anywhere in the JInternalFrame A first then clicking the close button. But the problem shows up when the user directly clicking the close button without activating the frame first, this time the closing event is not called. Is this the default behaviour or is this a bug ?
    Any help would be greatly appreciated.
    Setya

    OK....you can do that.  I would recommend the GSM version (AT&T), but you can buy it here and activate there.  Lot's of people do.......

  • Waiting a JInternalFrame to be closed before opening a new one

    Hello all
    I would like to wait a JInternalFrame to be closed by the user before opening a new one.
    Here is the sample code :
                   openRemote.getWindow().show();
                   Thread t = new Thread(new Runnable() {
                             public void run() {
                                  try {
                                       synchronized(openRemote.getWindow()) {
                                            System.out.println("Wait");
                                            openRemote.getWindow().wait();
                                            System.out.println("Closed");
                                       System.out.println("1111");
                                       //ChoosePhantomAction cpa = new ChoosePhantomAction();
                                       //cpa.actionPerformed(null);
                                       String phant = (String)JOptionPane.showInternalInputDialog(iFrame,"Phantom's name:", "Phantom selection",JOptionPane.PLAIN_MESSAGE,null,null, null);
                                       System.out.println("2222");
                                  } catch (java.lang.InterruptedException ie) {
                                       ie.printStackTrace();
                                  } catch (Exception exp) {
                                       exp.printStackTrace();
                   t.start();The first code line shows a JInternalFrame.
    I can see the JOptionPane on screen when i close the first frame but the message "22222" is never displayed. And i really can't understand why. Can it be due to the thread that uses Swing objects or the event dispatcher ?
    Thanks

    There are 2 files.
    The main one :
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class SSCCE extends JPanel {
        static JFrame frame;
         private JDesktopPane desktop = new JDesktopPane();
         private JInternalFrame iFrame = new JInternalFrame();
         public SSCCE() {
              setLayout(new BorderLayout());
              add(desktop, BorderLayout.CENTER);
              setPreferredSize(new Dimension(800,600));
              iFrame.setPreferredSize(new Dimension(300,200));
              JPanel panelCentre = new JPanel();
              panelCentre.setLayout(new BorderLayout());
              panelCentre.add(getMenusBar(), BorderLayout.NORTH);
              iFrame.getContentPane().add(panelCentre, BorderLayout.CENTER);
              iFrame.pack();
              iFrame.setVisible(true);
              desktop.add(iFrame);
        public JMenuBar getMenusBar() {
              JMenuBar menuBar = new JMenuBar();
              JMenu clickMenu = (JMenu) menuBar.add(new JMenu("Click here..."));
              createMenuItem(clickMenu, "...and now here", "click", new ClickAction());
              return menuBar;
        public JMenuItem createMenuItem(JMenu menu, String label,
                                                 String accessibleDescription, Action action) {
            JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(label));
              mi.getAccessibleContext().setAccessibleDescription(accessibleDescription);
              mi.addActionListener(action);
              if(action == null) {
                   mi.setEnabled(false);
              return mi;
        public static JFrame createFrame() {
              JFrame frame = new JFrame();
              WindowListener l = new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                             System.exit(0);
              frame.addWindowListener(l);
              return frame;
        class ClickAction extends AbstractAction {
            public void actionPerformed(ActionEvent e) {
                   final InternalPopUp ip1 = new InternalPopUp(desktop, "Please close to open 2nd window");
                   ip1.show();
                   Thread t = new Thread(new Runnable() {
                             public void run() {
                                  try {
                                       synchronized(ip1) {
                                            System.out.println("Wait");
                                            ip1.wait();
                                            System.out.println("Closed");
                                       System.out.println("1111");
                                       String phant = (String)JOptionPane.showInternalInputDialog(iFrame,"Enter something", "Enter something and check if 2222 is displayed in the console",JOptionPane.PLAIN_MESSAGE,null,null, null);
                                       System.out.println("2222");
                                  } catch (java.lang.InterruptedException ie) {
                                       ie.printStackTrace();
                                  } catch (Exception exp) {
                                       exp.printStackTrace();
                   t.start();
        public static void main(String s[]) {
              frame = createFrame();
              SSCCE sscce = new SSCCE();
              frame.setTitle("Sample test");
              frame.getContentPane().add(sscce, BorderLayout.CENTER);
              frame.pack();
              frame.setLocation(0,0);
              frame.setResizable(true);
              frame.setVisible(true);
    }The second one :
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.TitledBorder;
    class InternalPopUp extends JInternalFrame {
        private int PREFERRED_WIDTH = 250;
        private int PREFERRED_HEIGHT = 80;
         private JDesktopPane desktop = null;
         class PopupListener implements InternalFrameListener {
              JInternalFrame parent = null;          
              public PopupListener(JInternalFrame parent) {
                   this.parent = parent;
              public void internalFrameClosing(InternalFrameEvent e) {
              public void internalFrameClosed(InternalFrameEvent e) {
                   desktop.repaint();
                   synchronized(e.getSource()) {
                        e.getSource().notifyAll();
              public void internalFrameOpened(InternalFrameEvent e) {
              public void internalFrameIconified(InternalFrameEvent e) {
              public void internalFrameDeiconified(InternalFrameEvent e) {
              public void internalFrameActivated(InternalFrameEvent e) {
              public void internalFrameDeactivated(InternalFrameEvent e) {
         public InternalPopUp(JDesktopPane desktop, String text) {
              this.desktop = desktop;
              addInternalFrameListener(new PopupListener(this));
              setPreferredSize(new Dimension(PREFERRED_WIDTH,PREFERRED_HEIGHT));
              JPanel panelCentre = new JPanel();
              JButton close = new JButton(text);
              close.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             hidePopup();
              panelCentre.add(close);
              getContentPane().add(panelCentre);
              pack();
              desktop.add(this, JLayeredPane.POPUP_LAYER);
         public void hidePopup() {
              //super.hide();
              try {
                   setClosed(true);
              } catch (Exception e) {
              desktop.repaint();
    }I never see the "2222" sting in the console ...

  • SetVisible false at closing jInternalFrame

    I would have a button like the closing one, but it mustn't close really the interal frame, only set it not visible

    To get better help sooner, post a [_SSCCE_|http://mindprod.com/jgloss/sscce.html] that clearly demonstrates your problem.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    db

  • Closing JInternalFrame with Ctrl+F4 in windows

    Hi,
    I am using JDK 1.4 in Windows NT.I have a JFrame with menus and a desktoppane.In menu's click item i create a JInternalFrame(say jin) if it is not created and add it to desktoppane.If it is already created i just do a jin.setVisible(true) and use moveToFront of desktoppane.I have written a InternalFrameListener in which i make the jin invisible.When i click the close button in jin it hides correctly.When i click the menu it appears again.But when i use Ctrl+F4 key combination(which we use in Windows to close internalframes) it hides,but when i click the menu it dosen't reappear.I have tried to change the defaultcloseoperation to all values but it dosen't work.Is there a problem in my code or ?
    Thanks,
    Ranga.

    Assuming the above is correct:
    public void keyPressed(KeyEvent e){
    if( (e.isControlDown())&&(e.getKeyCode() == 115 ) )doDefaultCloseAction()); rykk

  • Intercepting user closing JInternalFrame

    I need to show a confirmation dialog, and do some cleanup, when a user clicks the "X" on a JInternalFrame. How is this done?
    Thanks! --- Eric

    make your internal frame implement InternalFrameListener, then add that listener to your internal frame. The InternalFrameListener will need you to implement the following methods:
    public void internalFrameOpened(InternalFrameEvent e){
    public void internalFrameClosed(InternalFrameEvent e){
    public void internalFrameClosing(InternalFrameEvent e){
    public void internalFrameActivated(InternalFrameEvent e){
    public void internalFrameIconified(InternalFrameEvent e){
    public void internalFrameDeiconified(InternalFrameEvent e){
    public void internalFrameDeactivated(InternalFrameEvent e){
    }Try putting what you need in the internalFrameClosing() method.

  • Closing JInternalFrame

    I've a problem with the 'X' (top left) of my JInternalFrame.
    I would like to capture the event when I click on the 'X', to execute more methods than a simply close.
    Thanks

    I've try this, with no result, my flag stay at 1...
    frameAssemblage.addInternalFrameListener(
         new InternalFrameAdapter()
    public void InternalFrameClosing (InternalFrameEvent
    t e)
         flagAssemblage = 0;
         );If you copied your code from your app, you put a capital "I" in your method name.

  • Closing JInternalFrame with Ctrl+F4 not using default close action

    If you have a JInternalFrame and set the default close operation to HIDE, when you close the frame with Ctrl+F4, the frame is disposed instead of hidden. Anyone know if this is the way it is suppose to work, or is this a bug?

    Assuming the above is correct:
    public void keyPressed(KeyEvent e){
    if( (e.isControlDown())&&(e.getKeyCode() == 115 ) )doDefaultCloseAction()); rykk

  • Closing JInternalFrame with ESC-Key?

    Hi all.
    Is there a way to close JInternalFrames with the ESC-Key?
    For JDialogs that works good (adding an action to the rootPane's ActionMap) but I cannot figure out how to add this functionality for JInternalFrames as well.
    Any hints?
    Regards
    Carsten

    try this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextButton extends JFrame
    JFormattedTextField tf1;
    Container con;
    public TextButton()
    con=getContentPane();
    con.setLayout(new FlowLayout());
    tf1=new JFormattedTextField();
    tf1.setValue(" ");
    tf1.addKeyListener(new KeyAdapter()
         public void keyPressed(KeyEvent ke)
         if(ke.getKeyCode()==10)     
    System.exit(0);
    con.add(tf1);
    setSize(400,400);
    setVisible(true);
    public static void main(String args[])
    new TextButton();
    }

  • Opening a Second JInternalFrame

    Below I have two classes InternalFrameDemo instantiates MyInternalFrame (extends javax.swing.JInternalFrame ) in doing this the application creates a JDesktopPane and creates a MyInternalFrame to put in it.
    What I want to happen is when the jButton1 on the MyInternalFrame is clicked is for a second MyInternalFrame to open and the first MyInternalFrame to close is this possible?
    I think that I would need to have the action Method in MyInternalFrame trigger a method call in the InternalFrameDemo and do the closing and opening of new MyInternalFrame from there?
    Thanks
    package components;
    import javax.swing.JInternalFrame;
    import javax.swing.JDesktopPane;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JMenuBar;
    import javax.swing.JFrame;
    import javax.swing.KeyStroke;
    import java.awt.event.*;
    import java.awt.*;
    public class InternalFrameDemo extends JFrame
    implements ActionListener {
    JDesktopPane desktop;
    public InternalFrameDemo() {
    super("InternalFrameDemo");
    int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset,
    screenSize.width - inset*2,
    screenSize.height - inset*2);
    desktop = new JDesktopPane();
    createFrame();
    setContentPane(desktop);
    setJMenuBar(createMenuBar());
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Document");
    menu.setMnemonic(KeyEvent.VK_D);
    menuBar.add(menu);
    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_N, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("new");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    return menuBar;
    public void actionPerformed(ActionEvent e) {
    if ("new".equals(e.getActionCommand())) {
    createFrame();
    } else {
    quit();
    protected void createFrame() {
    MyInternalFrame frame = new MyInternalFrame();
    frame.setVisible(true);
    desktop.add(frame);
    try {
    frame.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}
    MyInternalFrame frame2 = new MyInternalFrame();
    frame.setVisible(true);
    desktop.add(frame2);
    try {
    frame2.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}
    public void closeWin(){
    protected void quit() {
    System.exit(0);
    private static void createAndShowGUI() {
    JFrame.setDefaultLookAndFeelDecorated(true);
    InternalFrameDemo frame = new InternalFrameDemo();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    public static void main(String[] args) {     
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    /*MyInternalFrame */
    package components;
    public class MyInternalFrame extends javax.swing.JInternalFrame {
    @SuppressWarnings("unchecked")
    private void initComponents() {
    jButton1 = new javax.swing.JButton();
    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(152, 152, 152)
    .addComponent(jButton1)
    .addContainerGap(169, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(108, 108, 108)
    .addComponent(jButton1)
    .addContainerGap(147, Short.MAX_VALUE))
    pack();
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    this.dispose();
    private javax.swing.JButton jButton1;
    }

    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
    I think that I would need to have the action Method in MyInternalFrame trigger a method call in the InternalFrameDemo and do the closing and opening of new MyInternalFrame from there?Correct. So give it a try and see what happens.

  • Please help, Applet and JInternalFrame

    Hi,
    I have EXHAUSTEDresearch but to no avail on how to make the internal frame title ... closing button visible
    Currently it just covers up the entire area with the JInternalFrame
    The folwing is the code form the applet class
                   //JDesktopPane desktop = new JDesktopPane();
                   JDesktopPane desktop = new JDesktopPane();
                   SectionE obj = new SectionE();
                   //desktop.add(obj);
                   desktop.add(obj);
                   setContentPane(desktop);
                   desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
                   //setVisible(true);
    The internal frame is made from a class whic extends JInternalFrame and only has the following constructor
         public SectionE ()
              super("Document #",
                     true, //resizable
                     true, //closable
                     false,
                     true);
              setVisible(true);
              try {
              setSelected(true);
         } catch (java.beans.PropertyVetoException k) {k.printStackTrace();}
         }

    obj.setBounds(100,100,100,100);

  • Validating enabled and disabled menu bar in JInternalFrame

    hi,
    everybody.
    i have created a main window using JInternalFrame and JDesktopPane. The window has a menu bar in which document menu is used for closing the main window, while employee menu is used for adding new frame for the employee. while the login frame is displayed when the application is executed.
    my problem is, i want to validate that before login process, employee menu should be disabled, and after login is performed employee menu is enabled.
    the following is my code.
    please reply me as i am stucked with it.
    waiting for the reply
    thanks in advance.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    public class InternalFrameDemo extends JFrame implements ActionListener
    JDesktopPane desktop;
    public InternalFrameDemo()
    super("InternalFrameDemo");
    int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset*2, screenSize.height - inset*2);
    desktop = new JDesktopPane();
    setContentPane(desktop);
    desktop.setBackground(Color.white);
    setJMenuBar(createMenuBar());
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    createLogin();
    public JMenuBar createMenuBar()
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Document");
    menu.setMnemonic(KeyEvent.VK_D);
    menuBar.add(menu);
    JMenuItem menuItem = new JMenuItem("Quit");
    menuItem.setMnemonic(KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("quit");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    JMenu employee = new JMenu("Employee");
    employee.setMnemonic(KeyEvent.VK_E);
    employee.setActionCommand("employee");
    menuBar.add(employee);
    JMenuItem additem = new JMenuItem("Add");
    additem.setMnemonic(KeyEvent.VK_A);
    additem.setActionCommand("add");
    additem.addActionListener(this);
    employee.add(additem);
    return menuBar;
    public void actionPerformed(ActionEvent ae)
    String str = ae.getActionCommand();
    if(str.equals("add"))
    System.out.println("Employee Form Invoked");
    createEmployee();
    else if(str.equals("quit"))
    quit();
    public void createEmployee()
    MyEmployeeFrame employeeframe = new MyEmployeeFrame();
    employeeframe.setVisible(true);
    desktop.add(employeeframe);
    try
    employeeframe.setSelected(true);
    catch(Exception e)
    public void createLogin()
    MyLogin loginframe = new MyLogin();
    loginframe.setVisible(true);
    desktop.add(loginframe);
    try
    loginframe.setSelected(true);
    catch(Exception e){}
    public void quit()
    System.exit(0);
    private static void createAndShowGUI()
    JFrame.setDefaultLookAndFeelDecorated(true);
    InternalFrameDemo frame = new InternalFrameDemo();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,600);
    frame.setVisible(true);
    public static void main(String a[])
    createAndShowGUI();
    class MyEmployeeFrame extends JInternalFrame implements ActionListener
    JFrame employeeframe;
    JLabel labelfirstname;
    JLabel labellastname;
    JLabel labelage;
    JLabel labeladdress;
    JLabel labelcity;
    JLabel labelstate;
    JTextField textfirstname;
    JTextField textlastname;
    JTextField textage;
    JTextField textaddress;
    JTextField textcity;
    JTextField textstate;
    JButton buttonsave;
    FileOutputStream out;
    PrintStream p;
    String strfirstname,strlastname,strage,straddress,strcity,strstate;
    GridBagLayout gl;
    GridBagConstraints gbc;
    public MyEmployeeFrame()
    super("Employee Details",true,true,true,true);
    setSize(500,400);
    labelfirstname = new JLabel("First Name");
    labellastname = new JLabel("Last Name");
    labelage = new JLabel("Age");
    labeladdress = new JLabel("Address");
    labelcity = new JLabel("City");
    labelstate = new JLabel("State");
    textfirstname = new JTextField(10);
    textlastname = new JTextField(10);
    textage = new JTextField(5);
    textaddress = new JTextField(15);
    textcity = new JTextField(10);
    textstate = new JTextField(10);
    buttonsave = new JButton("Save");
    gl = new GridBagLayout();
    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 3;
    gl.setConstraints(labelfirstname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 3;
    gl.setConstraints(textfirstname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 5;
    gl.setConstraints(labellastname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 5;
    gl.setConstraints(textlastname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 7;
    gl.setConstraints(labelage,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 7;
    gl.setConstraints(textage,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 9;
    gl.setConstraints(labeladdress,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 9;
    gl.setConstraints(textaddress,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 11;
    gl.setConstraints(labelcity,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 11;
    gl.setConstraints(textcity,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 13;
    gl.setConstraints(labelstate,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 13;
    gl.setConstraints(textstate,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 17;
    gl.setConstraints(buttonsave,gbc);
    Container contentpane = getContentPane();
    contentpane.setLayout(gl);
    contentpane.add(labelfirstname);
    contentpane.add(textfirstname);
    contentpane.add(labellastname);
    contentpane.add(textlastname);
    contentpane.add(labelage);
    contentpane.add(textage);
    contentpane.add(labeladdress);
    contentpane.add(textaddress);
    contentpane.add(labelcity);
    contentpane.add(textcity);
    contentpane.add(labelstate);
    contentpane.add(textstate);
    contentpane.add(buttonsave);
    buttonsave.addActionListener(this);
    public void reset()
    textfirstname.setText("");
    textlastname.setText("");
    textage.setText("");
    textaddress.setText("");
    textcity.setText("");
    textstate.setText("");
    public void actionPerformed(ActionEvent ae)
    String str = ae.getActionCommand();
    System.out.println(str);
    if(str.equalsIgnoreCase("Save"))
    try
    out = new FileOutputStream("myfile.txt",true);
    p = new PrintStream( out );
    strfirstname = textfirstname.getText();
    strlastname = textlastname.getText();
    strage = textage.getText();
    straddress = textaddress.getText();
    strcity = textcity.getText();
    strstate = textstate.getText();
    p.print(strfirstname+"|");
    p.print(strlastname+"|");
    p.print(strage+"|");
    p.print(straddress+"|");
    p.print(strcity+"|");
    p.println(strstate);
    System.out.println("Record Saved");
    reset();
    p.close();
    catch (Exception e)
    System.err.println ("Error writing to file");
    class MyLogin extends JInternalFrame implements ActionListener
    JFrame loginframe;
    JLabel labelname;
    JLabel labelpassword;
    JTextField textname;
    JPasswordField textpassword;
    JButton okbutton;
    String name = "";
    FileOutputStream out;
    PrintStream p;
    Date date;
    GregorianCalendar gcal;
    GridBagLayout gl;
    GridBagConstraints gbc;
    public MyLogin()
    super("Login",true,true,true,true);
    setSize(400,300);
    gl = new GridBagLayout();
    gbc = new GridBagConstraints();
    labelname = new JLabel("User");
    labelpassword = new JLabel("Password");
    textname = new JTextField("",9);
    textpassword = new JPasswordField(5);
    okbutton = new JButton("OK");
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 5;
    gl.setConstraints(labelname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 2;
    gbc.gridy = 5;
    gl.setConstraints(textname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 10;
    gl.setConstraints(labelpassword,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 2;
    gbc.gridy = 10;
    gl.setConstraints(textpassword,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 15;
    gl.setConstraints(okbutton,gbc);
    Container contentpane = getContentPane();
    contentpane.setLayout(gl);
    contentpane.add(labelname);
    contentpane.add(labelpassword);
    contentpane.add(textname);
    contentpane.add(textpassword);
    contentpane.add(okbutton);
    okbutton.addActionListener(this);
    public void reset()
    textname.setText("");
    textpassword.setText("");
    public void run()
    try
    String text = textname.getText();
    String blank="";
    if(text.equals(blank))
    System.out.println("First Enter a UserName");
    else
    if(text != blank)
    date = new Date();
    gcal = new GregorianCalendar();
    gcal.setTime(date);
    out = new FileOutputStream("log.txt",true);
    p = new PrintStream( out );
    name = textname.getText();
    String entry = "UserName:- " + name + " Logged in:- " + gcal.get(Calendar.HOUR) + ":" + gcal.get(Calendar.MINUTE) + " Date:- " + gcal.get(Calendar.DATE) + "/" + gcal.get(Calendar.MONTH) + "/" + gcal.get(Calendar.YEAR);
    p.println(entry);
    System.out.println("Record Saved");
    reset();
    p.close();
    catch (IOException e)
    System.err.println("Error writing to file");
    public void actionPerformed(ActionEvent ae)
    String str = ae.getActionCommand();
    if(str.equals("OK"))
    run();
    loginframe.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    I realize this post is from a few days ago, but if you're still looking for help:
    This is my first thought on how to do this. Unfortunately, it's a bit messy. JMenuItems can be enabled and disabled but JMenus don't have this option...
    public class InternalFrameDemo extends JFrame implements ActionListener
        JDesktopPane desktop;
        JMenuBar menuBar;
        public InternalFrameDemo()
         setJMenuBar(createMenuBar());
         desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
         createLogin();
        public JMenuBar createMenuBar()
         menuBar = new JMenuBar();
         JMenu menu = new JMenu("Document");
         menu.setMnemonic(KeyEvent.VK_D);
         menuBar.add(menu);
         JMenuItem menuItem = new JMenuItem("Quit");
         menuItem.setMnemonic(KeyEvent.VK_Q);
         menuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.ALT_MASK));
         menuItem.setActionCommand("quit");
         menuItem.addActionListener(this);
         menu.add(menuItem);
         JMenuItem additem = new JMenuItem("Add");
         additem.setMnemonic(KeyEvent.VK_A);
         additem.setActionCommand("add");
         additem.addActionListener(this);
         employee.add(additem);
         return menuBar;
        public void createLogin()
         MyLogin loginframe = new MyLogin( menuBar );
         loginframe.setVisible(true);
         desktop.add(loginframe);
         try
             loginframe.setSelected(true);
         catch(Exception e)
    class MyLogin extends JInternalFrame implements ActionListener
        JMenuBar menuBar;
        public MyLogin( JMenuBar menuBar1 )
         super("Login",true,true,true,true);
         menuBar = menuBar1;
        public void actionPerformed(ActionEvent ae)
         String str = ae.getActionCommand();
         if(str.equals("OK"))
             run();
             JMenu employee = new JMenu("Employee");
             employee.setMnemonic(KeyEvent.VK_E);
             employee.setActionCommand("employee");
             menuBar.add(employee);
             loginframe.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

Maybe you are looking for

  • Spry select list code to wire it to html data table SET column?

    I am making a page based on Figure 15-14, Pg 878, in David Power's book, "Dw CS4 with CSS, Ajax and PHP. I have two separate html data tables hidden in the page, one for the specialties drop down select list and the other for the teachers master/deta

  • How to get the date n time for log in ODI

    Hi, I wanna ask, what is the syntax for getting the date n time when i specify the location of log for Interface. Thanks.

  • Tablet promotion misrepresented?

    I stopped by the Verizon Company Store in Perrysburg, OH for a few questions on an older phone acting up. While there the salesman promoted 2 "free" Ellipsis tablets offering no charge for the devices, a $20 discount on my current 10GB data plan to c

  • Where is the .jar file that contain this package oracle.security.idm

    Dear Everybody Could you tell me where is the .jar file that contain this package oracle.security.idm Thanks for your help

  • Video is cropping in swf

    Hi, The Camera  video is played well in other applications, but when I am using Camera in flash applications to play the live video, then video is cropped. Thanks Ram