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

The following examples show how to use java.awt.Container#removeAll() . 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: SelectionManagerTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void createTable(boolean isThreaded) {
	if (frame == null) {
		frame = new JFrame("GTree Test");
	}

	if (isThreaded) {
		table = new GTable(threadedModel);
	}
	else {
		table = new GTable(model);
	}

	Container contentPane = frame.getContentPane();
	contentPane.removeAll();
	contentPane.setLayout(new BorderLayout());
	frame.getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
	frame.setSize(1000, 400);
	frame.setVisible(true);

	waitForTableModel();
}
 
Example 2
Source File: JRViewer.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
*/
private void emptyContainer(Container container)
{
	Component[] components = container.getComponents();

	if (components != null)
	{
		for(int i = 0; i < components.length; i++)
		{
			if (components[i] instanceof Container)
			{
				emptyContainer((Container)components[i]);
			}
		}
	}

	components = null;
	container.removeAll();
	container = null;
}
 
Example 3
Source File: DDistinguishedNameChooser.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
private void layoutContentPane() {
	Container pane = getContentPane();
	pane.removeAll();
	pane.add(distinguishedNameChooser, "left, spanx, wrap");
	if (editable) {
		// when no DN was given, the default and reset button do exactly the same thing
		if (distinguishedName == null || distinguishedName.getRDNs().length == 0) {
			pane.add(jbReset, "right, spanx, wrap");
		} else {
			pane.add(jbReset, "right, spanx, split 2");
			pane.add(jbDefault, "wrap");
		}
	}
	pane.add(new JSeparator(), "spanx, growx, wrap");
	pane.add(jpButtons, "right, spanx");

	pack();
	validate();
	repaint();
}
 
Example 4
Source File: JRViewer.java    From nordpos with GNU General Public License v3.0 6 votes vote down vote up
/**
*/
private void emptyContainer(Container container)
{
	Component[] components = container.getComponents();

	if (components != null)
	{
		for(int i = 0; i < components.length; i++)
		{
			if (components[i] instanceof Container)
			{
				emptyContainer((Container)components[i]);
			}
		}
	}

	components = null;
	container.removeAll();
	container = null;
}
 
Example 5
Source File: MainFrame.java    From ShootPlane with Apache License 2.0 6 votes vote down vote up
public void loadGame() throws LineUnavailableException, UnsupportedAudioFileException, IOException {
Container c = this.getContentPane();
c.removeAll();
this.repaint();
if (this.gameLoadingPanel == null) {
    this.gameLoadingPanel = new GameLoadingPanel();
}

BoxLayout boxLayout = new BoxLayout(c, BoxLayout.Y_AXIS);
c.setLayout(boxLayout);
c.add(Box.createVerticalGlue());
c.add(this.gameLoadingPanel);
c.add(Box.createVerticalGlue());
this.gameLoadingPanel.loadingGame();

this.startGame();
   }
 
Example 6
Source File: IndependentWindow.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setComponent(Component comp) {
  Container cp = getContentPane();
  cp.removeAll();
  cp.add(comp, BorderLayout.CENTER);
  try {
    pack();
  } catch (IllegalArgumentException e) {
    // Ticket ID: HEM-237554
    // I'm using IceWM window manager under Linux, and it does not support changing the icon on the top left side of
    // the window.
    // This crashes the whole thing. I dont think this should be a fatal exception.
    // It would be helpful for future releases to catch this exception and let the program go ahead without the icon.
    log.error("Possible problem setting icon (?)", e);
  }
}
 
Example 7
Source File: AdditionalWizardPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Resets panel back after monitoring search. Implements <code>ProgressMonitor</code> interface method. */
public void reset() {
    Container container = (Container) getComponent();
    
    if(!container.isAncestorOf(getUI())) {
        container.removeAll();
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.weightx = 1.0;
        constraints.weighty = 1.0;
        constraints.fill = GridBagConstraints.BOTH;
        container.add(getUI(), constraints);
    }
}
 
Example 8
Source File: BasicReplaceResultsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void displayIssues(IssuesPanel issuesPanel) {
    if (issuesPanel != null) {
        showRefreshButton();
        removeButtons(btnNext, btnPrev, btnFlatView, btnTreeView,
                btnExpand, showDetailsButton);
        Container p = getContentPanel();
        p.removeAll();
        p.add(issuesPanel);
        validate();
        repaint();
    }
}
 
Example 9
Source File: BoxTabbedPaneUI.java    From pumpernickel with MIT License 5 votes vote down vote up
private void installExtraComponents(Container container,
		List<JComponent> components, boolean forceReinstall) {
	if (components == null)
		components = new ArrayList<>();
	Component[] oldComponents = container.getComponents();
	if (!Arrays.asList(oldComponents).equals(components)) {
		forceReinstall = true;
	}

	if (forceReinstall) {
		container.removeAll();
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 100;
		c.weightx = 1;
		c.weighty = 1;
		c.fill = GridBagConstraints.BOTH;
		for (JComponent jc : components) {
			container.add(jc, c);
			if (tabs.getTabPlacement() == SwingConstants.LEFT) {
				c.gridy--;
			} else if (tabs.getTabPlacement() == SwingConstants.RIGHT) {
				c.gridy++;
			} else {
				c.gridx++;
			}
			jc.removeComponentListener(extraComponentListener);
			jc.addComponentListener(extraComponentListener);

			for (Component oldComponent : oldComponents) {
				if (components.contains(oldComponent)) {
					oldComponent
							.removeComponentListener(extraComponentListener);
				}
			}
		}
		container.revalidate();
	}
	refreshExtraContainerVisibility();
}
 
Example 10
Source File: MainPanel.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
private void disposeInner(Container container) {
    for (Component c : container.getComponents()) {
        if (c instanceof Container) {
            Container c2 = (Container) c;
            disposeInner(c2);
        }
    }

    container.removeAll();
    container.setLayout(null);
    if (container instanceof TagEditorPanel) {
        Helper.emptyObject(container);
    }
}
 
Example 11
Source File: MagicInfoWindow.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private void refreshLayout() {
    final Container content = getContentPane();
    content.removeAll();
    final int titleHeight = title.getFontMetrics(body.getFont()).getMaxAscent();
    content.add(title, "h " + (titleHeight + 4) + "!");

    final String bodyText = body.getText();
    final String plainText = bodyText.replace("<html>", "").replace("</html>", "").replace("<br>", "");
    body.setText(plainText);
    final FontMetrics fontMetrics = body.getFontMetrics(body.getFont());
    body.setText(bodyText);

    final int maxWidth = 380;
    final String[] lineText = bodyText.replace("<html>", "").replace("</html>", "").trim().split("\r\n|\r|\n|<br>");
    int totalLines = 0;
    int totalWidth = 0;
    for (String text : lineText) {
        totalLines++;
        final int textWidth = fontMetrics.stringWidth(text.trim().isEmpty() ? "." : text);
        double calc1 = textWidth / ((double) maxWidth);
        final double calc2 = Math.ceil(calc1);
        long calc3 = Math.round(calc2);
        final int textLines = (int) (textWidth == 0 ? 1 : calc3 - 1);
        totalLines += textLines;
        final int W = textWidth > maxWidth ? maxWidth : textWidth;
        if (W > totalWidth) {
            totalWidth = W;
        }
    }

    final int lineHeight = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent();
    final int totalHeight = (totalLines + 1) * lineHeight;

    body.setMinimumSize(new Dimension(0, 0));
    body.setPreferredSize(new Dimension(totalWidth, totalHeight));
    body.setMaximumSize(new Dimension(maxWidth, totalHeight));

    content.add(body, "w 0:" + totalWidth + ":" + maxWidth + ", h " + totalHeight + "!");
    revalidate();
}
 
Example 12
Source File: MainFrame.java    From ShootPlane with Apache License 2.0 5 votes vote down vote up
private void popupMenuPanel() {
Container c = this.getContentPane();
c.removeAll();
this.repaint();
if (this.popupMenuPanel == null) {
    this.popupMenuPanel = new PopupMenuPanel(this);
}
BoxLayout boxLayout = new BoxLayout(c, BoxLayout.Y_AXIS);
c.setLayout(boxLayout);
c.add(Box.createVerticalGlue());
c.add(this.popupMenuPanel);
c.add(Box.createVerticalGlue());
this.validate();
   }
 
Example 13
Source File: MainFrame.java    From ShootPlane with Apache License 2.0 5 votes vote down vote up
private void startGame() throws LineUnavailableException, UnsupportedAudioFileException, IOException {
Container c = this.getContentPane();
c.removeAll();
this.repaint();
BorderLayout borderLayout = new BorderLayout();
c.setLayout(borderLayout);
this.gamePlayingPanel = new GamePlayingPanel();
c.add(this.gamePlayingPanel, BorderLayout.CENTER);
this.gamePlayingPanel.startGame();
long startTime = System.currentTimeMillis();
while (this.gamePlayingPanel.getMyPlane().isAlive()) {
    try {
	Thread.sleep(Config.GAME_PANEL_REPAINT_INTERVAL);
    } catch (InterruptedException e) {
	e.printStackTrace();
    }
}
long endTime = System.currentTimeMillis();
// add to score list
this.addScore(this.gamePlayingPanel.getScore(), endTime - startTime);
int option = JOptionPane.showConfirmDialog(this, "Game Over, Score:" + this.gamePlayingPanel.getScore()
	+ ", Start Again?", "Game Over", JOptionPane.YES_NO_OPTION);
switch (option) {
case JOptionPane.YES_OPTION:
    loadGame();
    break;
case JOptionPane.NO_OPTION:
    stopGame();
    break;
}
   }
 
Example 14
Source File: MainFrame.java    From ShootPlane with Apache License 2.0 5 votes vote down vote up
private void popupScorePanel(List<Score> sortedScoreList) {
Container c = this.getContentPane();
c.removeAll();
this.repaint();
if (this.popupScorePanel == null) {
    this.popupScorePanel = new Top10ScorePanel(this);
}
this.popupScorePanel.loadScore(sortedScoreList);
BoxLayout boxLayout = new BoxLayout(c, BoxLayout.Y_AXIS);
c.setLayout(boxLayout);
c.add(Box.createVerticalGlue());
c.add(this.popupScorePanel);
c.add(Box.createVerticalGlue());
this.validate();
   }
 
Example 15
Source File: GUIHelper.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * A copy of Curtis's method
	 * 
	 * https://github.com/openmicroscopy/bioformats/blob/v4.4.8/components/loci-plugins/src/loci/plugins/util/WindowTools.java#L72
	 * 
	 *
	 * @param pane
	 */
	public static void addScrollBars(Container pane) {
//        * <dependency>
//        * <groupId>${bio-formats.groupId}</groupId>
//        * <artifactId>loci_plugins</artifactId>
//        * <version>${bio-formats.version}</version>
//        * </dependency>

		GridBagLayout layout = (GridBagLayout) pane.getLayout();

		// extract components
		int count = pane.getComponentCount();
		Component[] c = new Component[count];
		GridBagConstraints[] gbc = new GridBagConstraints[count];
		for (int i = 0; i < count; i++) {
			c[i] = pane.getComponent(i);
			gbc[i] = layout.getConstraints(c[i]);
		}

		// clear components
		pane.removeAll();
		layout.invalidateLayout(pane);

		// create new container panel
		Panel newPane = new Panel();
		GridBagLayout newLayout = new GridBagLayout();
		newPane.setLayout(newLayout);
		for (int i = 0; i < count; i++) {
			newLayout.setConstraints(c[i], gbc[i]);
			newPane.add(c[i]);
		}

		// HACK - get preferred size for container panel
		// NB: don't know a better way:
		// - newPane.getPreferredSize() doesn't work
		// - newLayout.preferredLayoutSize(newPane) doesn't work
		Frame f = new Frame();
		f.setLayout(new BorderLayout());
		f.add(newPane, BorderLayout.CENTER);
		f.pack();
		final Dimension size = newPane.getSize();
		f.remove(newPane);
		f.dispose();

		// compute best size for scrollable viewport
		size.width += 25;
		size.height += 15;
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		int maxWidth = 7 * screen.width / 8;
		int maxHeight = 3 * screen.height / 4;
		if (size.width > maxWidth)
			size.width = maxWidth;
		if (size.height > maxHeight)
			size.height = maxHeight;

		// create scroll pane
		ScrollPane scroll = new ScrollPane() {
			private static final long serialVersionUID = 1L;

			public Dimension getPreferredSize() {
				return size;
			}
		};
		scroll.add(newPane);

		// add scroll pane to original container
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.gridwidth = GridBagConstraints.REMAINDER;
		constraints.fill = GridBagConstraints.BOTH;
		constraints.weightx = 1.0;
		constraints.weighty = 1.0;
		layout.setConstraints(scroll, constraints);
		pane.add(scroll);
	}