java - How to refresh custom bean in NetBeans? -
i want design relatively complex ui in netbeans ide. believed bring these components in 1 panel can intensify difficulty of maintenance of such panel.
for purpose i've broken down structure in multiple custom beans extending jpanel
. , in main panel i've included them choose bean button in palette toolbar.
every things looks ok when change 1 of child beans, change not take place on imported custom bean in main panel.
please point me out how can reload bean? thanks
for purpose i've broken down structure in multiple custom beans extending jpanel. , in main panel i've included them choose bean button in palette toolbar.
just starter i'd valid apporach , future visitors, following steps described here add panels main panel. same can done via drag & drop bean directly projects explorer design view.
every things looks ok when change 1 of child beans, change not take place on imported custom bean in main panel.
the short answer follows:
- open main panel in design view.
- go navigator tab.
- right click on form mainpanel , choose reload form option.
- the main panel updated.
however doesn't work , seems there long standing issue bug report on matter told it's not bug layout manager related stuff (not clear explanation though):
"the problem jpanel1 in myframe has layout code generated (grouplayout) - setting layout causes components removed. gui builder unfortunately not know there different container own layout since specified via custom code , not instantiated in gui form. can fix - set layout of jpanel1 in myframe flowlayout. default layout of jpanel, gui builder not generate layout code , custom panel left intact."
so, isn't clear why grouplayout causes behavior empirically solve have to:
- set different layout manager custom panels (i.e.: flowlayout or gridbaglayout).
- add panels main panel. if has panels, remove them , add them again. important custom panels have @ least 1 component.
- once previous steps done, custom panels layout manager can set grouplayout (free design) , still works.
- when custom panel modified, has compiled (f9) , main panel form needs updated through navigator explorer.
before go further i'd suggest don't set layout manager grouplayout (step 3) , use gridbaglayout instead. not favorite either imho it's better choice grouplayout. might want take reasons against grouplayout exemplified here , here (i'm sure there more here in so).
now, please consider following example (sorry extension).
1. create custom panel
go new file → swing gui forms → jpanel. name custompanel
2. set layout manager flowlayout
note: says default doesn't mean it's default used default por jpanel
class. i've said layout manager used default grouplayout.
3. add component panel , compile file
note generated code should (no grouplayout @ all):
public class custompanel extends javax.swing.jpanel { public custompanel() { initcomponents(); } @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() { jbutton1 = new javax.swing.jbutton(); jbutton1.settext("jbutton1"); add(jbutton1); }// </editor-fold> // variables declaration - not modify private javax.swing.jbutton jbutton1; // end of variables declaration }
4. create main panel
follow step 1 create new jpanel
, name mainpanel
.
5. add custompanel
mainpanel
either using palette , custom bean or drag , drop projects explorer , save changes.
note: can resize panel if want. if go navigator tab you'll see custom panel inside main panel:
6. modify custom panel
set layout grouplayout (free design) , modify needed. save changes , compile file.
7. reload main panel's form
go mainpanel
design view: still unchanged. go navigator tab , reload main panel's form:
awesome, main panel updated!
from now, every time modify custom panels have compile them , reload main panel's form (only steps 6 , 7 :)
Comments
Post a Comment