I am creating different frames for my GUI(Netbeans drag and drop) and in that i want to keep some buttons(sort of menu bar) visible in all the frames but the problem is when i copy the main frame and paste it,those buttons are there in the new frame with new names.So, i have to write the same code everytime.Is there any other easy approach for doing this.
Asked
Active
Viewed 287 times
1
-
1Don't use [multiple frames](http://stackoverflow.com/a/9554657/418556). This might be better suited to a `CardLayout` to swap between the views. – Andrew Thompson Mar 23 '12 at 17:54
-
but that multiple frames are not causing much problem to me but yeah this button problem is causing problem :S – Xara Mar 23 '12 at 18:06
-
*"not causing much problem"* It will, just wait. – Andrew Thompson Mar 23 '12 at 20:38
-
Indirectly, the answer to ***"but that multiple frames are not causing much problem to me"*** is given by you already, as ***"but yeah this button problem is causing problem :S"***, better stick to One `JFrame` rule and use `CardLayout` :-) Else you can make a separate Factory Class for your `JButton`'s SetUp GUI and use that again and again when needed, to create New `JButton`. – nIcE cOw Mar 24 '12 at 04:54
2 Answers
0
Make own MenuBar class, put your buttons there and use different instances of it in all your Frames is what you want I guess? So you have only to put different ActionListeners on each instance and not write same copy-pasted code over again.
Also you can make that frame as your own subclassed component which you can reuse from netbeans GUI builder like an JButton. Try to ask more precisely, hard to guess what you want.

lzdt
- 489
- 1
- 6
- 17