javafx - Static contextMenu in TreeCell -


in tutorial https://docs.oracle.com/javafx/2/ui_controls/tree-view.htm contextmenu added treecell allow item specific context.

instead of creating new contextmenu() every cell feasible in case make contextmenu static , create items inside static initializer e.g.

private final class textfieldtreecellimpl extends treecell<string> {     private static final contextmenu addmenu = new contextmenu();     static {         menuitem addmenuitem = new menuitem("add employee");         addmenu.getitems().add(addmenuitem);         addmenuitem.setonaction(new eventhandler() {             public void handle(event t) {                 treeitem newemployee =                      new treeitem<string>("new employee");                         gettreeitem().getchildren().add(newemployee);             }         });     } 

is there benefit in creating new contextmenu instance every cell?


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -