MCPcopy Create free account
hub / github.com/dorkbox/SystemTray / asSwingComponent

Method asSwingComponent

src/dorkbox/systemTray/Menu.java:325–365  ·  view source on GitHub ↗

@return a copy of this menu as a swing JMenu, with all elements converted to their respective swing elements. Modifications to the elements of the new JMenu will not affect anything, as they are all copies

()

Source from the content-addressed store, hash-verified

323 * @return a copy of this menu as a swing JMenu, with all elements converted to their respective swing elements. Modifications to the elements of the new JMenu will not affect anything, as they are all copies
324 */
325 @Override
326 public
327 JMenu asSwingComponent() {
328 JMenu jMenu = new JMenu();
329
330 if (getImage() != null) {
331 jMenu.setIcon(new ImageIcon(getImage().getAbsolutePath()));
332 }
333 jMenu.setText(getText());
334 jMenu.setToolTipText(getTooltip());
335 jMenu.setEnabled(getEnabled());
336 jMenu.setMnemonic(SwingUtil.INSTANCE.getVirtualKey(getShortcut()));
337
338
339 synchronized (menuEntries) {
340 for (final Entry menuEntry : menuEntries) {
341 if (menuEntry instanceof Menu) {
342 Menu entry = (Menu) menuEntry;
343 jMenu.add(entry.asSwingComponent());
344 }
345 else if (menuEntry instanceof Checkbox) {
346 Checkbox entry = (Checkbox) menuEntry;
347 jMenu.add(entry.asSwingComponent());
348 }
349 else if (menuEntry instanceof MenuItem) {
350 MenuItem entry = (MenuItem) menuEntry;
351 jMenu.add(entry.asSwingComponent());
352 }
353 else if (menuEntry instanceof Separator) {
354 Separator entry = (Separator) menuEntry;
355 jMenu.add(entry.asSwingComponent());
356 }
357 else if (menuEntry instanceof Status) {
358 Status entry = (Status) menuEntry;
359 jMenu.add(entry.asSwingComponent());
360 }
361 }
362 }
363
364 return jMenu;
365 }
366
367 /**
368 * This removes a menu entry from the menu.

Callers

nothing calls this directly

Calls 10

asSwingComponentMethod · 0.95
getImageMethod · 0.80
setToolTipTextMethod · 0.80
setTextMethod · 0.65
setEnabledMethod · 0.65
addMethod · 0.65
getTextMethod · 0.45
getTooltipMethod · 0.45
getEnabledMethod · 0.45
getShortcutMethod · 0.45

Tested by

no test coverage detected