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);
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) {
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();
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);
/** * 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; }
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);
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);
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"); } } });
Component[] allComp = f.getComponents(); Component c = f.getComponents()[0]; f.remove(c); f.setVisible(false); add(c); validate();
/** * 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; }
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);
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();
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"); } } });
((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();
/** * 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; }
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);
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(); }