• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create multiple windows in netbeans GUI builder?  RSS feed

 
Louis Lewis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to create a program in netbeans GUI builder. I would like to open a separate form window on a mouse click on one of the menu items, and then to have that form return information to the main window. However, I cannot figure out how to make separate windows in one GUI builder application, let alone have them communicate. Anyone know how? Is this even possible in the GUI builder?

P.S: If you're going to tell me not to use the GUI builder, please just don't comment. I'm trying it for one program as an expiriment, and will make my decision at the end whether or not to continue using it.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Open your project and choose File/New file menu command. In the New file form, choose "Swing GUI Forms" in the list of categories and choose the appropriate form type in the File types panel.

I was using GUI builders only briefly, so I might not have discovered all the features, but I'm not aware of any possibility on how to link two form together automatically. In my opinion, you'll have to program all this yourself (ie. open a child form and then retrieve the data into an instance of some class and pass that to the parent form upon close).
 
Louis Lewis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks. I created the form, and figured out how to open it on a menu item click in the main window, and then also how to close the window when the submit button is pressed. Still working on how to get the form to return information though
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you having difficulties with?

One possible way is to create a class that will represent the data of your form, and add a method to the form which would create a new instance of that class and set its properties using data of the components on the form. Such as:

In your parent form, you'll keep the reference to the child form and call its getFormData method when the form successfully closes.
 
Louis Lewis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, that's an interesting idea. But how do I get the main class to look at the values of the data class as soon as the JForm is closed? I could add a window closing event to the actual JForm itself, but what I really want is for the main class to know when the JForm is closing, and to get all of its values right before it closes.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you should use a modal dialog/form. When you call setVisible(true) on a modal form, the setVisible call won't return until the modal dialog is closed, hidden or destroyed. This means you don't have to add any window closing event manually. See the modality in Swing tutorial.

Edit: we're now strictly in the Swing territory, so I've added this thread to the Swing forum as well.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!