Java Code Examples for java.awt.Container#remove()

The following examples show how to use java.awt.Container#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QPopup.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
public void hide() {
	Window w = SwingUtilities.getWindowAncestor(contents);
	Container parent = contents.getParent();
	if (parent != null) {
		Rectangle r = contents.getBounds();
		parent.remove(contents);
		parent.repaint(r.x, r.y, r.width, r.height);
	}
	if (w instanceof RootPaneContainer) {
		RootPaneContainer rpc = (RootPaneContainer) w;
		Boolean b = (Boolean) rpc.getRootPane()
				.getClientProperty(PROPERTY_IS_QPOPUP);
		if (Boolean.TRUE.equals(b)) {
			w.setVisible(false);
			w.dispose();
		}
	}
}
 
Example 2
Source File: InternalWindow.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Close the window. Either deletes or hides it, according to the policy
 * set with {@link #setHideOnClose}.
 */
public void close() {
	if (hideOnClose) {
		setVisible(false);
	} else {
		Container parent = InternalWindow.this.getParent();
		if (parent != null) {
			parent.remove(InternalWindow.this);
			parent.validate();
			parent.repaint();
		}
	}
	// notify listeners
	for (CloseListener listener : closeListeners) {
		listener.windowClosed(this);
	}
}
 
Example 3
Source File: WizardDialog.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handles a click on the "previous" button, by displaying the previous panel in the sequence.
 */
public void previous() {
    if (this.step > 0) {
        final WizardPanel previousPanel = getWizardPanel(this.step - 1);
        // tell the panel that we are returning
        previousPanel.returnFromLaterStep();
        final Container content = getContentPane();
        content.remove(this.currentPanel);
        content.add(previousPanel);
        this.step = this.step - 1;
        this.currentPanel = previousPanel;
        setTitle("Step " + (this.step + 1));
        enableButtons();
        pack();
    }
}
 
Example 4
Source File: Handler.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Docks the associated toolbar at the secified edge and indicies.
 */
public void dockToolBar(final int edge, final int row, final int index) {
    final Container target = ourDockLayout.getTargetContainer();
    if (target == null)
        return;

    target.remove(ourToolBar);
    final JDialog floatFrame = getFloatingFrame();
    if (floatFrame != null) {
        floatFrame.setVisible(false);
        floatFrame.getContentPane().remove(ourToolBar);
    }

    ourConstraints.setEdge(edge);
    ourConstraints.setRow(row);
    ourConstraints.setIndex(index);

    target.add(ourToolBar, ourConstraints);
    ourToolBarShouldFloat = false;

    target.validate();
    target.repaint();
}
 
Example 5
Source File: AbstractPetriNetViewComponent.java    From PIPE with MIT License 5 votes vote down vote up
/**
 * Remove the view from its container
 */
protected final void removeFromContainer() {
    Container c = getParent();

    if (c != null) {
        c.remove(this);
    }
}
 
Example 6
Source File: BoxTabbedPaneUI.java    From pumpernickel with MIT License 5 votes vote down vote up
private void removeNonUIResources(Container c) {
	for (Component comp : c.getComponents()) {
		if (!(comp instanceof UIResource)) {
			c.remove(comp);
		}
	}
}
 
Example 7
Source File: WizardDialog.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Displays the next step in the wizard sequence.
 */
public void next() {

    WizardPanel nextPanel = getWizardPanel(this.step + 1);
    if (nextPanel != null) {
        if (!this.currentPanel.canRedisplayNextPanel()) {
            nextPanel = this.currentPanel.getNextPanel();
        }
    }
    else {
        nextPanel = this.currentPanel.getNextPanel();
    }

    this.step = this.step + 1;
    if (this.step < this.panels.size()) {
        this.panels.set(this.step, nextPanel);
    }
    else {
        this.panels.add(nextPanel);
    }

    final Container content = getContentPane();
    content.remove(this.currentPanel);
    content.add(nextPanel);

    this.currentPanel = nextPanel;
    setTitle("Step " + (this.step + 1));
    enableButtons();
    pack();

}
 
Example 8
Source File: Frame.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
private void placeToolbar() {
	String loc = AppPreferences.TOOLBAR_PLACEMENT.get();
	Container contents = getContentPane();
	contents.remove(toolbar);
	mainPanelSuper.remove(toolbar);
	if (AppPreferences.TOOLBAR_HIDDEN.equals(loc)) {
		; // don't place value anywhere
	} else if (AppPreferences.TOOLBAR_DOWN_MIDDLE.equals(loc)) {
		toolbar.setOrientation(Toolbar.VERTICAL);
		mainPanelSuper.add(toolbar, BorderLayout.WEST);
	} else { // it is a BorderLayout constant
		Object value = BorderLayout.NORTH;
		for (Direction dir : Direction.cardinals) {
			if (dir.toString().equals(loc)) {
				if (dir == Direction.EAST)
					value = BorderLayout.EAST;
				else if (dir == Direction.SOUTH)
					value = BorderLayout.SOUTH;
				else if (dir == Direction.WEST)
					value = BorderLayout.WEST;
				else
					value = BorderLayout.NORTH;
			}
		}
		contents.add(toolbar, value);
		boolean vertical = value == BorderLayout.WEST || value == BorderLayout.EAST;
		toolbar.setOrientation(vertical ? Toolbar.VERTICAL : Toolbar.HORIZONTAL);
	}
	contents.validate();
}
 
Example 9
Source File: DefaultDesktopManager.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to remove the desktopIcon of <b>f</b> is necessary.
 *
 * @param f the {@code JInternalFrame} for which to remove the
 *          {@code desktopIcon}
 */
protected void removeIconFor(JInternalFrame f) {
    JInternalFrame.JDesktopIcon di = f.getDesktopIcon();
    Container c = di.getParent();
    if(c != null) {
        c.remove(di);
        c.repaint(di.getX(), di.getY(), di.getWidth(), di.getHeight());
    }
}
 
Example 10
Source File: DefaultDesktopManager.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the frame from its parent and adds its
 * <code>desktopIcon</code> to the parent.
 * @param f the <code>JInternalFrame</code> to be iconified
 */
public void iconifyFrame(JInternalFrame f) {
    JInternalFrame.JDesktopIcon desktopIcon;
    Container c = f.getParent();
    JDesktopPane d = f.getDesktopPane();
    boolean findNext = f.isSelected();
    desktopIcon = f.getDesktopIcon();
    if(!wasIcon(f)) {
        Rectangle r = getBoundsForIconOf(f);
        desktopIcon.setBounds(r.x, r.y, r.width, r.height);
        // we must validate the hierarchy to not break the hw/lw mixing
        desktopIcon.revalidate();
        setWasIcon(f, Boolean.TRUE);
    }

    if (c == null || d == null) {
        return;
    }

    if (c instanceof JLayeredPane) {
        JLayeredPane lp = (JLayeredPane)c;
        int layer = JLayeredPane.getLayer(f);
        JLayeredPane.putLayer(desktopIcon, layer);
    }
    d.setComponentOrderCheckingEnabled(true);
    c.remove(f);
    c.add(desktopIcon);
    if (findNext) {
        if (d.selectFrame(true) == null) {
            // The icon is the last frame.
            f.restoreSubcomponentFocus();
        }
    }
    c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
}
 
Example 11
Source File: UnitLabel.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean addCargo(Component comp, Unit carrier, CargoPanel cargoPanel) {
    Unit unit = ((UnitLabel)comp).getUnit();
    if (carrier.canAdd(unit)) {
        Container oldParent = comp.getParent();
        if (cargoPanel.igc().boardShip(unit, carrier)) {
            ((UnitLabel) comp).setSmall(false);
            if (oldParent != null) oldParent.remove(comp);
            cargoPanel.update();
            return true;
        }
    }
    return false;
}
 
Example 12
Source File: FlatPopupFactory.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
private void hideMediumWeightDropShadow() {
	mediumWeightPanel.removeComponentListener( mediumPanelListener );

	Container parent = dropShadowPanel.getParent();
	if( parent != null ) {
		Rectangle bounds = dropShadowPanel.getBounds();
		parent.remove( dropShadowPanel );
		parent.repaint( bounds.x, bounds.y, bounds.width, bounds.height );
	}
}
 
Example 13
Source File: MainFrame.java    From blog with Apache License 2.0 5 votes vote down vote up
public void setContent(Component component) {
	Container contentPane = getContentPane();
	if (currentContent != null) {
		contentPane.remove(currentContent);
	}
	contentPane.add(component, BorderLayout.CENTER);
	currentContent = component;
	contentPane.doLayout();
	repaint();
}
 
Example 14
Source File: Handler.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Hides the associated toolbar by removing it from its dock or by closing
 * its client floating frame.
 */
public void hideToolBar() {
    final Container target = ourDockLayout.getTargetContainer();
    target.remove(ourToolBar);
    final JDialog floatFrame = getFloatingFrame();
    if (floatFrame != null) {
        floatFrame.setVisible(false);
        floatFrame.getContentPane().remove(ourToolBar);
    }

    target.validate();
    target.repaint();
}
 
Example 15
Source File: MainFrame.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void showFindTextPane(@Nullable final String text) {
  final TabTitle current = getFocusedTab();
  if (current != null && this.tabPane.getCurrentTitle().getProvider().doesSupportPatternSearch()) {

    FindTextPanel panel = this.currentFindTextPanel.get();
    if (panel == null) {
      panel = new FindTextPanel(this, text);
      panel.updateUI(current);
    }
    this.currentFindTextPanel.set(panel);

    final Container currentParent = panel.getParent();
    if (currentParent != null) {
      currentParent.remove(panel);
      currentParent.revalidate();
      currentParent.repaint();
    }

    final boolean mmdEditor = current.getProvider().getEditor().getEditorContentType() == EditorContentType.MINDMAP;
    
    panel.setEnableSearchFile(mmdEditor);
    panel.setEnableSearchNote(mmdEditor);
    panel.setEnableSearchURI(mmdEditor);
    panel.setEnableSearchTopicText(mmdEditor);
    
    if (!this.tabPane.getCurrentTitle().getProvider().showSearchPane(panel)) {
      this.mainPanel.add(panel, BorderLayout.SOUTH);
    }

    this.mainPanel.revalidate();
    this.mainPanel.repaint();

    panel.requestFocus();
  }
}
 
Example 16
Source File: GroupChatInvitationUI.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Removes this interface from it's parent.
 */
private void removeUI() {
    final Container par = getParent();
    if (par != null) {
        par.remove(this);
        par.invalidate();
        par.validate();
        par.repaint();
    }

}
 
Example 17
Source File: MessagePanel.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
  final Container parent = this.getParent();
  if (parent != null) {
    parent.remove(this);
    if (ACTIVE_MESSAGES.decrementAndGet()<=0){
      Main.getApplicationFrame().getGlassPane().setVisible(false);
    }
    parent.revalidate();
  }
}
 
Example 18
Source File: ModifiableJOptionPane.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public static void reverseOKCancel(JButton ok, JButton cancel) {
    if(ResourceEditorApp.IS_MAC) {
        Container c = ok.getParent();
        c.remove(ok);
        c.add(ok);
    }
}
 
Example 19
Source File: EuropePanel.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Component add(Component comp, boolean editState) {
    if (editState) {
        if (!(comp instanceof UnitLabel)) {
            logger.warning("Invalid component: " + comp);
            return null;
        }
        final Unit unit = ((UnitLabel)comp).getUnit();

        if (unit.getTradeRoute() != null) {
            if (!getGUI().confirmClearTradeRoute(unit)
                || !igc().assignTradeRoute(unit, null)) return null;
        }

        Location dest = destination;
        if (unit.isInEurope()) {
            dest = getGUI().showSelectDestinationDialog(unit);
            if (dest == null) return null; // user aborted
        }
        
        final ClientOptions co = getClientOptions();
        if (!co.getBoolean(ClientOptions.AUTOLOAD_EMIGRANTS)
            && unit.isInEurope()
            && !(destination instanceof Europe)
            && europeanDocksPanel.getComponentCount() > 0
            && unit.hasSpaceLeft()) {
            StringTemplate locName = destination
                .getLocationLabelFor(unit.getOwner());
            if (!getGUI().confirm(null, StringTemplate
                    .template("europePanel.leaveColonists")
                    .addStringTemplate("%newWorld%", locName),
                    unit, "ok", "cancel")) return null;
        }

        igc().moveTo(unit, dest);
        if (dest instanceof Europe) {
            ; // Assume this works
        } else {
            // Fail if still in Europe if told to leave
            if (unit.isInEurope()) return null;
        }
        Container parent = comp.getParent();
        if (parent != null) parent.remove(comp);
        inPortPanel.update();
        europeanDocksPanel.update();
        cargoPanel.update();
        if (unit == cargoPanel.getCarrier()) {
            cargoPanel.setCarrier(null);
        }
    }

    Component c = add(comp);
    revalidate();
    EuropePanel.this.refresh();
    return c;
}
 
Example 20
Source File: Visual.java    From SikuliX1 with MIT License 4 votes vote down vote up
public void removeFrom(Container container) {
  for (Visual follower : getFollowers()) {
    follower.removeFrom(container);
  }
  container.remove(this);
}