java - One JMenuBar and multiple JPanels -


i have problem application gui. create 1 global jmenubar , share other jpanels, if want assign multi jpanels have error:

#

"the menubar component added parent component more once.

•panelall.add(menubar);

•paneltask.add(menubar);"

#

/**  * initialize contents of frame.  */ private void initialize() {     frame = new jframe();      jpanel panelall = new jpanel();     frame.getcontentpane().add(panelall, "name_218556506364138");     panelall.setlayout(null);      jmenubar menubar = new jmenubar();     menubar.setbounds(0, 0, 795, 21);     panelall.add(menubar);      jpanel paneltask = new jpanel();     frame.getcontentpane().add(paneltask, "name_218567310779840");     paneltask.setlayout(null);     paneltask.add(menubar);      jpanel panelmytask = new jpanel();     frame.getcontentpane().add(panelmytask, "name_218578712986622");     panelmytask.add(menubar);      jpanel panelmysoftware = new jpanel();     frame.getcontentpane().add(panelmysoftware, "name_218590026900741");     panelmysoftware.add(menubar);      jpanel panelmydevices = new jpanel();     frame.getcontentpane().add(panelmydevices, "name_218598029981563");     panelmydevices.add(menubar); } } 

image

i don't think idea add jmenubar jpanel, if insist...

a jmenubar can added 1 container, need create more instances of jmenubar. should work without problems if use command pattern.

//first instance jmenubar taskmenubar = new myjmenubarimplementation(); jpanel panelmytask = new jpanel(); frame.getcontentpane().add(panelmysoftware, "name_xxx"); panelmytask.add(taskmenubar);  //second instance jmenubar softwaremenubar = new myjmenubarimplementation(); jpanel panelmysoftware = new jpanel(); frame.getcontentpane().add(panelmysoftware, "name_yyy"); panelmysoftware.add(softwaremenubar);  //and on... 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -