java.awt.Container.remove()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(323)

本文整理了Java中java.awt.Container.remove()方法的一些代码示例,展示了Container.remove()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Container.remove()方法的具体详情如下:
包路径:java.awt.Container
类名称:Container
方法名:remove

Container.remove介绍

[英]Removes the component, specified by index, from this container.
[中]从此容器中删除由index指定的组件。

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

private static void useProgressBarHelper(Container parent, JComponent add, JComponent remove) {
 GridBagConstraints c = new GridBagConstraints();
 c.fill = GridBagConstraints.BOTH;
 c.weightx = 1.7;
 parent.remove(remove);
 parent.add(add,c);
 parent.validate();
 parent.repaint();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
  @Override
frame.getContentPane().add(canvas);
frame.pack();
frame.setLocationRelativeTo(null);
frame.getContentPane().remove(canvas);
frame.getContentPane().add(canvas);

代码示例来源:origin: stackoverflow.com

private static final Dimension LABEL_SIZE = new Dimension(60, 40);
private GridLayout gridlayout = new GridLayout(GRID_ROWS, GRID_COLS, GAP, GAP);
private JPanel backingPanel = new JPanel(gridlayout);
private JPanel[][] panelGrid = new JPanel[GRID_ROWS][GRID_COLS];
private JLabel redLabel = new JLabel("Red", SwingConstants.CENTER);
  for (int row = 0; row < GRID_ROWS; row++) {
    for (int col = 0; col < GRID_COLS; col++) {
      panelGrid[row][col] = new JPanel(new GridBagLayout());
      backingPanel.add(panelGrid[row][col]);
  redLabel.setBackground(Color.red.brighter().brighter());
  redLabel.setPreferredSize(LABEL_SIZE);
  panelGrid[4][3].add(redLabel);
  panelGrid[1][1].add(blueLabel);
      clickedPanel.remove(dragLabel);
      clickedPanel.revalidate();
      clickedPanel.repaint();
      return;
    remove(dragLabel); // remove dragLabel for drag layer of JLayeredPane
    JPanel droppedPanel = (JPanel) backingPanel.getComponentAt(me.getPoint());
    if (droppedPanel == null) {

代码示例来源:origin: org.netbeans.api/org-openide-dialogs

public void updateMessage() {
  if (messageComponent != null) {
    getContentPane().remove(messageComponent);
    JComponent toAdd = new JPanel (new BorderLayout ());
    toAdd.add (messageComponent, BorderLayout.CENTER);
    messageComponent = toAdd;
  getContentPane().add(messageComponent, BorderLayout.CENTER);

代码示例来源:origin: stackoverflow.com

frame.getContentPane().add(button);
  frame.pack();
  frame.setVisible(true);
progressBar.setStringPainted(true);
progressBar.setIndeterminate(true);
dialog.getContentPane().add(progressBar);
dialog.pack();
dialog.setModal( false );
System.out.println("done");
JLabel label = new JLabel("Task Complete");
dialog.getContentPane().remove(progressBar);
dialog.getContentPane().add(label);
dialog.getContentPane().validate();

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

panel = new JPanel();
  panel.setOpaque(false);
  panel.setBorder(BorderFactory.createLineBorder(Color.RED));
panel.getParent().remove(panel);
putClientProperty("dirty", null);
repaint();

代码示例来源:origin: stackoverflow.com

public Component add(Component c) {
  ensurePopupMenuCreated();
  popupMenu.add(c);
  return c;
public Component add(Component c, int index) {
  ensurePopupMenuCreated();
  popupMenu.add(c, index);
  return c;
public void remove(JMenuItem item) {
  if(popupMenu != null){
    popupMenu.remove(item);
public void remove(Component c) {
  if(popupMenu != null){
    popupMenu.remove(c);

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

/**
 * Hides the findPanel's toplevel window and returns its location.
 * If the dispose is true, the findPanel is removed from its parent
 * and the toplevel window is disposed.
 * 
 * @param dispose boolean to indicate whether the findPanels toplevel
 *   window should be disposed.
 * @return the location of the window if visible, or the last known
 *   location.
 */
protected Point hideSharedFindPanel(boolean dispose) {
  if (findPanel == null) return null;
  Window window = SwingUtilities.getWindowAncestor(findPanel);
  Point location = lastFindDialogLocation;
  if (window != null) {
    // PENDING JW: can't remember why it it removed always?
    if (window.isVisible()) {
      location = window.getLocationOnScreen();
      window.setVisible(false);
    }
    if (dispose) {
      findPanel.getParent().remove(findPanel);
      window.dispose();
    } 
  }
  return location;
}

代码示例来源:origin: stackoverflow.com

layeredPane.addMouseListener( this );
layeredPane.addMouseMotionListener( this );
getContentPane().add(layeredPane);
chessBoard = new JPanel();
chessBoard.setLayout( new GridLayout(8, 8) );
chessBoard.setPreferredSize( boardSize );
chessBoard.setBounds(0, 0, boardSize.width, boardSize.height);
layeredPane.add(chessBoard, JLayeredPane.DEFAULT_LAYER);
    JPanel square = new JPanel( new BorderLayout() );
    square.setBackground( (i + j) % 2 == 0 ? Color.red : Color.white );
    chessBoard.add( square );
layeredPane.remove(chessPiece);
chessPiece.setVisible(true);
  parent.remove(0);
  parent.add( chessPiece );
  parent.validate();
frame.setDefaultCloseOperation( DISPOSE_ON_CLOSE );
frame.setResizable( false );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible(true);

代码示例来源:origin: bobbylight/RSyntaxTextArea

private void setBottomPanel() {
  final JPanel panel = new JPanel(new BorderLayout());
  panel.add(new JSeparator(), BorderLayout.NORTH);
  if (cp.getComponentCount()==2) { // Skip first time through
    Component comp = cp.getComponent(0);
    cp.remove(0);
    JScrollPane sp = new JScrollPane(comp);
    Border emptyBorder = BorderFactory.createEmptyBorder();
    sp.setBackground(textArea.getBackground());
    sp.getViewport().setBackground(textArea.getBackground());
    cp.add(sp);
    cp.remove(0);
  cp.add(panel, BorderLayout.SOUTH);

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void actionPerformed(ActionEvent e){
    if (itemSwitchTab.getText().equals("Switch to tab #2")){
      canvasPanel1.remove(canvas);
      canvasPanel2.add(canvas, BorderLayout.CENTER);
      currentPanel = canvasPanel2;
      itemSwitchTab.setText("Switch to tab #1");
    }else if (itemSwitchTab.getText().equals("Switch to tab #1")){
      canvasPanel2.remove(canvas);
      canvasPanel1.add(canvas, BorderLayout.CENTER);
      currentPanel = canvasPanel1;
      itemSwitchTab.setText("Switch to tab #2");
    }
  }
});

代码示例来源:origin: stackoverflow.com

Component[] allComp = f.getComponents();
Component c = f.getComponents()[0];
f.remove(c);
f.setVisible(false);
add(c);
validate();

代码示例来源:origin: org.swinglabs.swingx/swingx-core

/**
 * Hides the findPanel's toplevel window and returns its location.
 * If the dispose is true, the findPanel is removed from its parent
 * and the toplevel window is disposed.
 * 
 * @param dispose boolean to indicate whether the findPanels toplevel
 *   window should be disposed.
 * @return the location of the window if visible, or the last known
 *   location.
 */
protected Point hideSharedFindPanel(boolean dispose) {
  if (findPanel == null) return null;
  Window window = SwingUtilities.getWindowAncestor(findPanel);
  Point location = lastFindDialogLocation;
  if (window != null) {
    // PENDING JW: can't remember why it it removed always?
    if (window.isVisible()) {
      location = window.getLocationOnScreen();
      window.setVisible(false);
    }
    if (dispose) {
      findPanel.getParent().remove(findPanel);
      window.dispose();
    } 
  }
  return location;
}

代码示例来源:origin: stackoverflow.com

getContentPane().add(actionPanel,BorderLayout.NORTH);
getContentPane().add(demoPanel,BorderLayout.CENTER);
  setVisible(true);
setTitle("White Space");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
  add(label1);
  if(withGlue){
    add(Box.createVerticalGlue());
  spinner.setValue(new Integer(0));
  withGlue = (withGlue == true ? false:true);
  whiteSpace.getContentPane().remove(demoPanel);
  demoPanel = new DemoPanel();
  whiteSpace.getContentPane().add(demoPanel,BorderLayout.CENTER);
public void stateChanged(ChangeEvent e) {
  int strutValue = (Integer) spinner.getValue();
  whiteSpace.getContentPane().remove(demoPanel);
  demoPanel = new DemoPanel(strutValue);
  whiteSpace.getContentPane().add(demoPanel,BorderLayout.CENTER);

代码示例来源:origin: stackoverflow.com

private static final int           TOP               = 0x03;
private static final int           BOTTOM            = 0x04;
private final JPanel               basePanel         = new JPanel();
private final ParentType           parent;
private final Object               lock              = new Object();
  glassPane = new JPanel();
  glassPane.setOpaque(false);
  glassPane.addMouseListener(new MouseAdapter() {
    statusPanel.add(new JButton("Slide Right") {
  if (parent instanceof JFrame) {
    ((JFrame) parent).getContentPane().setBackground(jPanels.get(0).getBackground());
    parent.remove(basePanel);
    parent.validate();
    parent.remove(basePanel);
    parent.validate();
    parent.remove(basePanel);
    parent.validate();

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void actionPerformed(ActionEvent e) {
    if (itemRemoveCanvas.getText().equals("Remove Canvas")){
      currentPanel.remove(canvas);
      itemRemoveCanvas.setText("Add Canvas");
    }else if (itemRemoveCanvas.getText().equals("Add Canvas")){
      currentPanel.add(canvas, BorderLayout.CENTER);
      itemRemoveCanvas.setText("Remove Canvas");
    }
  }
});

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

((Window) floatingToolBar).setVisible(false);
floatingToolBar.getContentPane().remove(toolBar);
Integer constraint = constraintBeforeFloating;
if (dockingSource == null) {
  UIManager.removePropertyChangeListener(propertyListener);
dockingSource.add(toolBar, constraint.intValue());
dockingSource.invalidate();
Container dockingSourceParent = dockingSource.getParent();

代码示例来源:origin: org.swinglabs.swingx/swingx-all

/**
 * Hides the findPanel's toplevel window and returns its location.
 * If the dispose is true, the findPanel is removed from its parent
 * and the toplevel window is disposed.
 * 
 * @param dispose boolean to indicate whether the findPanels toplevel
 *   window should be disposed.
 * @return the location of the window if visible, or the last known
 *   location.
 */
protected Point hideSharedFindPanel(boolean dispose) {
  if (findPanel == null) return null;
  Window window = SwingUtilities.getWindowAncestor(findPanel);
  Point location = lastFindDialogLocation;
  if (window != null) {
    // PENDING JW: can't remember why it it removed always?
    if (window.isVisible()) {
      location = window.getLocationOnScreen();
      window.setVisible(false);
    }
    if (dispose) {
      findPanel.getParent().remove(findPanel);
      window.dispose();
    } 
  }
  return location;
}

代码示例来源:origin: stackoverflow.com

b.setBorder(new LineBorder(Color.black, 2));
b.setPreferredSize(new Dimension(600, 10));
panel = new JPanel(new GridLayout(0, 1));
panel.add(b);
f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(panel, "Center");
f.add(getCheckBoxPanel(), "South");
f.setLocation(200, 200);
f.pack();
f.setVisible(true);
    int count = panel.getComponentCount();
    if (count > 0) {
      panel.remove(0);
JPanel panel2 = new JPanel();
panel2.add(checkValidate);
panel2.add(checkReValidate);

代码示例来源:origin: stackoverflow.com

private javax.swing.JPanel containerPanel;
 private void initComponents() {
   jLabel1 = new javax.swing.JLabel();
   jLabel1.setText("Shop Name");
   gridBagConstraints = new java.awt.GridBagConstraints();
   gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
   gridBagConstraints.weightx = 1.0;
   gridBagConstraints.weighty = 1.0;
   containerPanel = new javax.swing.JPanel();
   containerPanel.add(jLabel1);
   add(containerPanel, gridBagConstraints);
 }
 //Variable declarationg
 private javax.swing.JLabel jLabel1;
 //Setter for Shop Name
 public void setArmorImage(JLabel shopLabel) {
   containerPanel.remove(jLabel1);
   containerPanel.add(shopLabel);
   jLabel1 = shopLabel;
   revalidate();
 }

相关文章

微信公众号

最新文章

更多

Container类方法