0

I have created a login form where users will enter their credentials and navigate to other frame. This frame to frame transition is working fine. But I also added a admin login from a invisible label in the bottom.

When the admin clicks the invisible label on the user login frame (NewJFrame), a custom login panel (Admin) should be opened.

But when I click the label, JPanel is not showing.

private void jLabel6MouseClicked(java.awt.event.MouseEvent evt) 
{
    Admin o = new Admin();           // Admin is a login panel
    NewJFrame o1= new NewJFrame();   
    o1.add(o);                     // Throwing an Exception here

    // TODO add your handling code here:
}    
blackpanther
  • 10,998
  • 11
  • 48
  • 78
Malwaregeek
  • 2,274
  • 3
  • 15
  • 18
  • Also, consider these [alternatives](http://stackoverflow.com/q/9554636/230513) to multiple frames. – trashgod Aug 02 '13 at 19:57
  • What's the Exception that's getting thrown? – splungebob Aug 02 '13 at 20:26
  • And where is this MouseListener code? From within NewJFrame (terrible name, btw)? Instead of trying to launch a new login frame for admins, perhaps just switch the layout. `CardLayout` would be worth investigating. – splungebob Aug 02 '13 at 20:32
  • This mouse listener code is in frame (NewJFrame), on which there is a label jLabel6, on clicking it, a panel (Admin) should open. – Malwaregeek Aug 03 '13 at 06:43
  • @splungebob Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: adding a window to a container – Malwaregeek Aug 03 '13 at 06:44
  • Then it appears that Admin extends JFrame (or some other subclass of Window) instead of JPanel. You can't do that. – splungebob Aug 03 '13 at 14:24

1 Answers1

0

you are adding it on mouse click ? i think you should add it at start and on mouse click , just make it visible by yourPanel.setVisible(true);

Omar Bahir
  • 1,237
  • 5
  • 20
  • 48