0

I originally made a complex GUI in JFrame Form by the form editor. There are several Jpanels inside the frame.

Now I am thinking of reusing some of the JPanels in other JFrames. I know it is possible to copy and paste the JPanel, but what I really want to do is factoring out the JPanel to make it a class. Is it possible to do it in Netbeans?

EDIT: Thanks for the advices, it was really helpful, but not solving my problem. I still need to factor out the panel. Say if I have a Panel with several child panels inside. (eg: tabbed panel) I would like to design each of the child panel separately instead of doing them all together in a single class. That's my understanding of OOP. I did not do it at the first place because I was not familiar with netbeans nor I was an good designer. Now I realize I need to reuse some of the child panels. Am I able to factor out the code for each panel and make it a class without redoing the work? I used GridbagLayout.

Alex
  • 2,915
  • 5
  • 28
  • 38
  • I assume you mean you've built the UI using the form editor? – MadProgrammer Jun 19 '14 at 07:45
  • @peeskillet I do not want to redo it from scratch. I want to factor out my JPanel from my JFrame – Alex Jun 19 '14 at 07:48
  • 1
    Create a new `JPanel` form, select all the fields on the previous panel and copy them and past them into the new form. This won't guarantee that everything will be brought across (event handlers, required code), but should give you a start – MadProgrammer Jun 19 '14 at 07:49
  • Usually we don't use multiple JFrames in single application – vels4j Jun 19 '14 at 07:50
  • @MadProgrammer The biggest pain is that I have to redo the layout... so there is no way to factor out a Component from a JFrame? – Alex Jun 19 '14 at 07:52
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Jun 19 '14 at 07:58
  • Why would you have to "redo the layout?" – trashgod Jun 19 '14 at 08:17
  • Set the layout of the new panel as the same as the panel, it should maintain the layout properties (depending on the layout) – MadProgrammer Jun 19 '14 at 09:03
  • @trashgod because it lost everything when I copy and paste the componets inside. I used Gridbag layout. – Alex Jun 19 '14 at 14:04
  • Right click on the new `JPanel` and set the desired layout; use the same properties as the used on the frame's content pane. – trashgod Jun 19 '14 at 19:22

0 Answers0