1

is it possible when I click a JButton in my Java UI they'll be another JFrame that pops out and it includes other Forms or other layout? for example, I click the "View Employee" button they'll be another form that's going to pop out but it contains the employee information on another window?

bharath
  • 14,283
  • 16
  • 57
  • 95
user962206
  • 15,637
  • 61
  • 177
  • 270
  • 1
    Generally an application would have only one `JFrame`, use `JDialog` instances for pop-ups, but also investigate the plethora of possibilities for including more than one collection of controls in one (top level) GUI. See also [this answer](http://stackoverflow.com/questions/6037573/how-do-i-add-a-bunch-of-jpanels-to-my-jframe-using-java-swing/6037667#6037667). – Andrew Thompson Nov 21 '11 at 10:58

1 Answers1

2

better would be implemnts CardLayout rather than to create a new Top-Level Container(s)

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • +1 agree, for [example](http://stackoverflow.com/questions/5654926/implementing-back-forward-buttons-in-swing/5655843#5655843). – trashgod Nov 21 '11 at 11:15
  • yes Java Swing default http://download.oracle.com/javase/tutorial/uiswing/layout/index.html , because these Containers stay in the mamory untill current JVM instance exists, sure there is possible create a new Container, then not JFrame (too hard manage actions betweens two JFrames) but JDialog and re-use that for another actions, to avoiding create a new Container on Fly – mKorbel Nov 21 '11 at 11:37
  • I was thinking of showing an EmployeeProfile, will the JDialog suffice that? – user962206 Nov 21 '11 at 11:57
  • if you want any form of popup window then JDialog is best way how to do it, for exclusive window you have to look for setModal/ModalityTypes, if you want to re-use this JDialog the don't forget to set `my&Dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);` – mKorbel Nov 21 '11 at 12:12
  • how about for logging in? Since I am creating a payroll system, and I need a log in button, then it will bring the user to another form? is that possible? – user962206 Nov 22 '11 at 03:15
  • yes you'll create JDialog, if loggin passed then you'll create the aplication JFrame – mKorbel Nov 22 '11 at 06:04