/** * Installs/resets a ComponentListener to resize the * given window to minWidth/Height if needed. * * @param window * @param minWidth * @param minHeight */ public static void setMinimumSizeManager(Window window, int minWidth, int minHeight) { ComponentListener[] listeners = window.getComponentListeners(); ComponentListener listener = null; for (ComponentListener l : listeners) { if (l instanceof MinSizeComponentListener) { listener = l; break; } } if (listener == null) { window.addComponentListener(new MinSizeComponentListener( window, minWidth, minHeight)); } else { ((MinSizeComponentListener) listener).resetSizes(minWidth, minHeight); } }
@Override public void hierarchyChanged(HierarchyEvent e) { // if we are not talking about a rootpane being added to a window, quit and never try again if (!((e.getChangedParent() instanceof Dialog) || (e.getChangedParent() instanceof Frame))) { e.getChanged().removeHierarchyListener(this); return; } // if we are something other than a change event, quit if ((e.getID() != HierarchyEvent.HIERARCHY_CHANGED) || !(e.getChanged() instanceof JRootPane)) { return; } Window w = (Window) e.getChangedParent(); if (w != null) { if (!Arrays.asList(w.getComponentListeners()).contains(WINDOW_ROUNDER)) { w.addComponentListener(WINDOW_ROUNDER); } e.getChanged().removeHierarchyListener(this); } } };
frame.validate(); for (ComponentListener l : frame.getComponentListeners()) { if (l instanceof FullscreenComponentListener) { frame.removeComponentListener(l);
window.getComponentListeners().add(listener.getListener());