@Override public void actionPerformed(ActionEvent e) { Component root = null; Container parent = SwingUtilities.getUnwrappedParent((Component) e.getSource()); if (parent instanceof JPopupMenu) { JPopupMenu popup = (JPopupMenu) parent; root = SwingUtilities.getRoot(popup.getInvoker()); } else if (parent instanceof JToolBar) { JToolBar toolbar = (JToolBar) parent; if (((BasicToolBarUI) toolbar.getUI()).isFloating()) { root = SwingUtilities.getWindowAncestor(toolbar).getOwner(); } else { root = SwingUtilities.getRoot(toolbar); } } else { root = SwingUtilities.getRoot(parent); } if (root instanceof Window) { Window window = (Window) root; window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } }
public static void unfloatToolBar(JToolBar tb) { ToolBarUI tbUI = tb.getUI(); if (tbUI instanceof BasicToolBarUI) ((BasicToolBarUI) tbUI).setFloating(false, null); }
public static void floatToolBar(JToolBar tb, Point p) { ToolBarUI tbUI = tb.getUI(); if (tbUI instanceof BasicToolBarUI) ((BasicToolBarUI) tbUI).setFloating(false, p); }
public void testSetGetUI() { BasicToolBarUI ui = new BasicToolBarUI(); toolBar.setUI(ui); assertSame(ui, toolBar.getUI()); }