List of usage examples for javax.swing JComponent remove
public void remove(int index)
From source file:Main.java
public static void swapComponentsAndResizeUI(JComponent ui, JComponent current, JComponent next) { ui.remove(current); ui.add(next);/*ww w . j ava 2 s . c o m*/ current = next; Component c = ui.getTopLevelAncestor(); if (c instanceof Window) { Window w = (Window) c; w.pack(); } }
From source file:edu.ku.brc.af.tasks.subpane.StatsPane.java
/** * Loads all the panels.//w ww . j av a 2 s . co m */ protected void init() { JComponent parentComp = upperDisplayComp != null ? upperDisplayComp : this; for (Component c : comps) { parentComp.remove(c); } comps.clear(); if (centerPanel != null) { remove(centerPanel); } Element rootElement = null; try { rootElement = AppContextMgr.getInstance().getResourceAsDOM(resourceName); if (rootElement == null) { throw new RuntimeException("Couldn't find resource [" + resourceName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } // count up rows and column StringBuilder rowsDef = new StringBuilder(128); boolean hasResBundle = false; Element panelEl = (Element) rootElement.selectObject("/panel"); String resBundleName = XMLHelper.getAttr(panelEl, "resource", null); if (StringUtils.isNotEmpty(resBundleName)) { hasResBundle = true; UIRegistry.loadAndPushResourceBundle(resBundleName); } List<?> rows = rootElement.selectNodes("/panel/row"); //$NON-NLS-1$ int maxCols = 0; for (Object obj : rows) { Element rowElement = (Element) obj; List<?> boxes = rowElement.selectNodes("box"); //$NON-NLS-1$ maxCols = Math.max(maxCols, boxes.size()); if (rowsDef.length() > 0) { rowsDef.append(",15dlu,"); //$NON-NLS-1$ } rowsDef.append("top:p"); //$NON-NLS-1$ } int preferredWidth = PREFERREDWIDTH; int spacing = SPACING; String colDefs = createDuplicateJGoodiesDef("f:min(" + preferredWidth + "px;p)", spacing + "px", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ maxCols); FormLayout formLayout = new FormLayout(colDefs, rowsDef.toString()); PanelBuilder builder = new PanelBuilder(formLayout); CellConstraints cc = new CellConstraints(); int y = 1; for (Object obj : rows) { Element rowElement = (Element) obj; int x = 1; List<?> boxes = rowElement.selectNodes("box"); //$NON-NLS-1$ for (Object bo : boxes) { Element boxElement = (Element) bo; String type = getAttr(boxElement, "type", "box"); //$NON-NLS-1$ //$NON-NLS-2$ int colSpan = getAttr(boxElement, "colspan", 1); //$NON-NLS-1$ Component comp = null; if (type.equalsIgnoreCase("bar chart")) //$NON-NLS-1$ { String statName = getAttr(boxElement, "name", null); //$NON-NLS-1$ if (isNotEmpty(statName)) { BarChartPanel bcp = (BarChartPanel) StatsMgr.createStatPane(statName); int width = colSpan > 1 ? ((maxCols * preferredWidth) + ((maxCols - 1) * spacing)) : preferredWidth; // We start by assuming the chart will be square which is why we use // preferredWidth as the height, and then we calculate the new width bcp.setPreferredChartSize(width, preferredWidth); comp = bcp; //comp.setSize(new Dimension(preferredWidth, preferredWidth)); //comp.setPreferredSize(new Dimension(preferredWidth, preferredWidth)); //comp.invalidate(); //comp.doLayout(); //System.out.println(comp.getSize()); validate(); doLayout(); repaint(); } } else // The default is "Box" { comp = processBox(boxElement, hasResBundle); } if (comp != null) { comps.add(comp); if (colSpan == 1) { builder.add(comp, cc.xy(x, y)); } else { builder.add(comp, cc.xywh(x, y, colSpan, 1)); } x += 2; } } // boxes y += 2; } if (hasResBundle) { UIRegistry.popResourceBundle(); } setBackground(bgColor); JPanel statPanel = builder.getPanel(); statPanel.setBackground(Color.WHITE); boolean hasUpper = upperDisplayComp != null; builder = new PanelBuilder(new FormLayout("C:P:G", hasUpper ? "50px,p,20px,p" : "p")); //$NON-NLS-1$ //$NON-NLS-2$ if (hasUpper) { y = 2; builder.add(upperDisplayComp, cc.xy(1, y)); y += 2; } else { y = 1; } builder.add(statPanel, cc.xy(1, y)); centerPanel = builder.getPanel(); centerPanel.setBackground(Color.WHITE); //For Tiling if (isTiled()) { centerPanel.setOpaque(false); setOpaque(false); statPanel.setOpaque(false); } centerPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(centerPanel, BorderLayout.CENTER); if (updateBtn == null) { PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,4px", "4px,p,4px")); //pb.setOpaque(false); updateBtn = new FadeBtn(UIRegistry.getResourceString("STS_UPDATE")); pb.add(updateBtn, cc.xy(2, 2)); pb.getPanel().setBackground(bgColor); add(pb.getPanel(), BorderLayout.SOUTH); updateBtn.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { init(); } }); } centerPanel.validate(); validate(); doLayout(); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(StatsPane.class, ex); log.error(ex); ex.printStackTrace(); } }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected void closeWindow(Window window, WindowOpenInfo openInfo) { if (!disableSavingScreenHistory) { screenHistorySupport.saveScreenHistory(window, openInfo.getOpenMode()); }/* w ww . j a va 2 s. c o m*/ switch (openInfo.getOpenMode()) { case DIALOG: { JDialog dialog = (JDialog) openInfo.getData(); dialog.setVisible(false); dialog.dispose(); cleanupAfterModalDialogClosed(window); fireListeners(window, tabs.size() != 0); break; } case NEW_TAB: case NEW_WINDOW: { JComponent layout = (JComponent) openInfo.getData(); layout.remove(DesktopComponentsHelper.getComposition(window)); if (isMainWindowManager) { tabsPane.remove(layout); } WindowBreadCrumbs windowBreadCrumbs = tabs.get(layout); if (windowBreadCrumbs != null) { windowBreadCrumbs.clearListeners(); windowBreadCrumbs.removeWindow(); } tabs.remove(layout); stacks.remove(windowBreadCrumbs); fireListeners(window, tabs.size() != 0); if (!isMainWindowManager) { closeFrame(getFrame()); } break; } case THIS_TAB: { JComponent layout = (JComponent) openInfo.getData(); final WindowBreadCrumbs breadCrumbs = tabs.get(layout); if (breadCrumbs == null) throw new IllegalStateException("Unable to close screen: breadCrumbs not found"); breadCrumbs.removeWindow(); Window currentWindow = breadCrumbs.getCurrentWindow(); if (!stacks.get(breadCrumbs).empty()) { Map.Entry<Window, Integer> entry = stacks.get(breadCrumbs).pop(); putToWindowMap(entry.getKey(), entry.getValue()); } JComponent component = DesktopComponentsHelper.getComposition(currentWindow); Window currentWindowFrame = (Window) currentWindow.getFrame(); final java.awt.Component focusedCmp = windowOpenMode.get(currentWindowFrame).getFocusOwner(); if (focusedCmp != null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { focusedCmp.requestFocus(); } }); } layout.remove(DesktopComponentsHelper.getComposition(window)); if (App.getInstance().getConnection().isConnected()) { layout.add(component); if (isMainWindowManager) { // If user clicked on close button maybe selectedIndex != tabsPane.getSelectedIndex() // Refs #1117 int selectedIndex = 0; while ((selectedIndex < tabs.size()) && (tabsPane.getComponentAt(selectedIndex) != layout)) { selectedIndex++; } if (selectedIndex == tabs.size()) { selectedIndex = tabsPane.getSelectedIndex(); } setActiveWindowCaption(currentWindow.getCaption(), currentWindow.getDescription(), selectedIndex); } else { setTopLevelWindowCaption(currentWindow.getCaption()); component.revalidate(); component.repaint(); } } fireListeners(window, tabs.size() != 0); break; } default: throw new UnsupportedOperationException(); } }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected JComponent showWindowThisTab(Window window, String caption, String description) { getDialogParams().reset();//from ww w . java2s. c o m window.setWidth("100%"); window.setHeight("100%"); JComponent layout; if (isMainWindowManager) { layout = (JComponent) tabsPane.getSelectedComponent(); } else { layout = (JComponent) frame.getContentPane().getComponent(0); } WindowBreadCrumbs breadCrumbs = tabs.get(layout); if (breadCrumbs == null) throw new IllegalStateException("BreadCrumbs not found"); Window currentWindow = breadCrumbs.getCurrentWindow(); Window currentWindowFrame = (Window) currentWindow.getFrame(); windowOpenMode.get(currentWindowFrame).setFocusOwner(frame.getFocusOwner()); Set<Map.Entry<Window, Integer>> set = windows.entrySet(); boolean pushed = false; for (Map.Entry<Window, Integer> entry : set) { if (entry.getKey().equals(currentWindow)) { windows.remove(currentWindow); stacks.get(breadCrumbs).push(entry); pushed = true; break; } } if (!pushed) { stacks.get(breadCrumbs).push(new AbstractMap.SimpleEntry<>(currentWindow, null)); } windows.remove(window); layout.remove(DesktopComponentsHelper.getComposition(currentWindow)); JComponent component = DesktopComponentsHelper.getComposition(window); layout.add(component); breadCrumbs.addWindow(window); if (isMainWindowManager) { setActiveWindowCaption(caption, description, tabsPane.getSelectedIndex()); } else { setTopLevelWindowCaption(caption); component.revalidate(); component.repaint(); } return layout; }