Java Code Examples for java.awt.Component#validate()

The following examples show how to use java.awt.Component#validate() . These examples are extracted from open source projects. 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
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 2
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 3
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 4
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 5
/**
 * Computes the preferred size on the EventDispatcherThread.
 */
public void run() {
  retval = null;
  try {
    final Component component = getComponent();
    if ( component instanceof Window == false && isOwnPeerConnected() == false ) {
      peerSupply.pack();
      contentPane.add( component );
      contentPane.validate();
      component.validate();
    } else if ( isOwnPeerConnected() ) {
      retval = component.getSize();
      return;
    } else {
      component.validate();
    }
    retval = component.getPreferredSize();
  } finally {
    cleanUp();
  }
}
 
Example 6
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 7
Source Project: netbeans   File: AnimationLayer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Paints the current state (i.e. the state corresponding to the current
 * phase) of the given component.
 *
 * @param g graphics context.
 * @param comp component to paint.
 */
private void paintComponent(Graphics g, Component comp) {
    Rectangle bounds = currentBounds(comp);
    float alpha = currentAlpha(comp);
    Graphics gg = g.create(bounds.x, bounds.y, bounds.width, bounds.height);
    if (alpha != 1f) {
        AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
        ((Graphics2D)gg).setComposite(alphaComposite);
    }
    comp.setBounds(bounds);
    comp.validate();
    // Intentionally using print instead of paint.
    // Print doesn't use double buffering and it solves some mysterious
    // problems with modified clip during painting of containers.
    // BTW: animated transitions library also uses print()
    if (comp instanceof JComponent) {
        comp.print(gg);
    } else {
        java.awt.peer.ComponentPeer peer = FakePeerSupport.getPeer(comp);
        if (peer != null) {
            peer.paint(gg);
        }
    }
    gg.dispose();
}
 
Example 8
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 9
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 10
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 11
Source Project: Java8CN   File: JLayeredPane.java    License: Apache License 2.0 6 votes vote down vote up
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 12
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 13
protected void addImpl(Component comp, Object constraints, int index) {
    int layer;
    int pos;

    if(constraints instanceof Integer) {
        layer = ((Integer)constraints).intValue();
        setLayer(comp, layer);
    } else
        layer = getLayer(comp);

    pos = insertIndexForLayer(layer, index);
    super.addImpl(comp, constraints, pos);
    comp.validate();
    comp.repaint();
    validateOptimizedDrawing();
}
 
Example 14
Source Project: constellation   File: FindTopComponent.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Shades the FindCriteriaPanels blue and white consecutively.
 */
private void shader() {
    int panelFindCount = 0;

    for (int i = 0; i < panelFind.getComponentCount(); i++) {
        final Component item = panelFind.getComponent(i);
        if (item instanceof FindCriteriaPanel) {
            final Color color;

            // Shade every second panel:
            if ((panelFindCount % 2) == 0) {
                color = PALE_BLUE;
            } else {
                color = Color.WHITE;
            }

            item.setBackground(color);

            item.validate();
            item.repaint();

            panelFindCount++;
        }
    }

    panelFind.validate();
    panelFind.repaint();
}
 
Example 15
public void paintEditor(Graphics g) {
    Component component = grid.getEditorComponent();
    if (component == null) {
        return;
    }

    int editingRow = grid.getEditingRow();
    int editingColumn = grid.getEditingColumn();
    Rectangle cellBounds = grid.getCellBounds(editingRow, editingColumn);
    component.setBounds(cellBounds);
    component.validate();
    component.requestFocus();
}
 
Example 16
/**
 * Register a component that should watch for default font size changes.
 * Typically the component should be the top level window.
 *
 * @param component root component for the tree whose font size shall be
 * 	changed at default font size changes
 */
public static void watchFontSize(final Component component) {
	final SettingChangeListener listener = new SettingChangeAdapter(FONT_SIZE_PROPERTY,
			Integer.toString(DEFAULT_FONT_SIZE)) {
		@Override
		public void changed(String newValue) {
			int size = MathHelper.parseIntDefault(newValue, DEFAULT_FONT_SIZE);
			scaleComponentFonts(component, size);
			component.validate();
			component.setSize(component.getPreferredSize());
		}
	};

	WtWindowManager.getInstance().registerSettingChangeListener(FONT_SIZE_PROPERTY, listener);

	/*
	 * Dialogs typically get disposed when they are closed. Remove the
	 * listener so that the the dialog and its subcomponents can be
	 * reclaimed by the garbage collector.
	 */
	if (component instanceof Window) {
		((Window) component).addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent e) {
				WtWindowManager.getInstance().deregisterSettingChangeListener(FONT_SIZE_PROPERTY, listener);
			}
		});
	}
}
 
Example 17
Source Project: pumpernickel   File: PaddingInfo.java    License: MIT License 5 votes vote down vote up
/**
 * This makes some visual changes to the component and its children. Shortly
 * after calling this method, the <code>restore()</code> method needs to be
 * called.
 */
private static void prep(Component c) {
	if (c instanceof JComponent) {
		JComponent jc = (JComponent) c;
		if (jc.isOpaque()) {
			jc.setOpaque(false);
			jc.putClientProperty(USED_TO_BE_OPAQUE, Boolean.TRUE);
		}

		Dimension preferredSize = c.getPreferredSize();
		if (greaterThanOrEqualTo(jc.getSize(), preferredSize) == false) {
			jc.putClientProperty(SIZE, c.getSize());
			jc.setSize(preferredSize);
		}
	}
	if (c instanceof JSlider) {
		JSlider s = (JSlider) c;
		ChangeListener[] listeners = s.getChangeListeners();
		int mid = (s.getMinimum() + s.getMaximum()) / 2;
		if (mid != s.getValue()) {
			s.putClientProperty(CHANGE_LISTENERS, listeners);
			for (int a = 0; a < listeners.length; a++) {
				s.removeChangeListener(listeners[a]);
			}
			s.putClientProperty(SLIDER_VALUE, new Integer(s.getValue()));
			s.setValue(mid);
		}
	}
	if (c instanceof Container) {
		Container c2 = (Container) c;
		for (int a = 0; a < c2.getComponentCount(); a++) {
			prep(c2.getComponent(a));
		}
	}
	if (c.isValid() == false)
		c.validate();
}
 
Example 18
Source Project: MobyDroid   File: JFrame_Main.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent me) {
    // dragging
    if (dragging) {
        int x = me.getXOnScreen();
        int y = me.getYOnScreen();
        // Move frame by the mouse delta
        setLocation(getLocationOnScreen().x + x - prevX, getLocationOnScreen().y + y - prevY);
        prevX = x;
        prevY = y;
    }
    // resizing
    if (resizing) {
        Component component = me.getComponent();
        Rectangle rect = prevR;
        int xInc = me.getXOnScreen() - prevX;
        int yInc = me.getYOnScreen() - prevY;

        //  Resizing the West or North border affects the size and location
        switch (outcode) {
            case Rectangle.OUT_TOP:
                rect.y += yInc;
                rect.height -= yInc;
                break;
            case Rectangle.OUT_TOP + Rectangle.OUT_LEFT:
                rect.y += yInc;
                rect.height -= yInc;
                rect.x += xInc;
                rect.width -= xInc;
                break;
            case Rectangle.OUT_LEFT:
                rect.x += xInc;
                rect.width -= xInc;
                break;
            case Rectangle.OUT_LEFT + Rectangle.OUT_BOTTOM:
                rect.height += yInc;
                rect.x += xInc;
                rect.width -= xInc;
                break;
            case Rectangle.OUT_BOTTOM:
                rect.height += yInc;
                break;
            case Rectangle.OUT_BOTTOM + Rectangle.OUT_RIGHT:
                rect.height += yInc;
                rect.width += xInc;
                break;
            case Rectangle.OUT_RIGHT:
                rect.width += xInc;
                break;
            case Rectangle.OUT_RIGHT + Rectangle.OUT_TOP:
                rect.y += yInc;
                rect.height -= yInc;
                rect.width += xInc;
                break;
            default:
                break;
        }

        prevX = me.getXOnScreen();
        prevY = me.getYOnScreen();

        component.setBounds(rect);
        component.validate();
        component.repaint();
    }
}
 
Example 19
Source Project: netbeans   File: FontPanel.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Called whenever any of the controls on the panel gets an event
 */
private void setValue(String errorMsg) {

    boolean sizeChanged;
    boolean styleChanged;

    int oldSize = size;
    size = 12;
    try {
        size = Integer.parseInt(tfSize.getText());
        if (size <= 0) {
            IllegalArgumentException iae = new IllegalArgumentException();
            /* LATER
            UIExceptions.annotateUser (iae, null,
            size == 0 ? "CTL_InvalidValueWithParam", tfSize.getText () : // NOI18N
            "CTL_NegativeSize", // NOI18N
            null, null);
            tfSize.setText (String.valueOf (font.getSize ()));
             */
            throw iae;
        }
        updateSizeList(size);
    } catch (NumberFormatException e) {
        /* LATER
        UIExceptions.annotateUser (e, null,
        "CTL_InvalidValueWithExc", // NOI18N
        null, null);
        tfSize.setText (String.valueOf (font.getSize ()));
         */
        throw e;
    }
    sizeChanged = size != oldSize;

    int oldStyle = style;
    int i = lStyle.getSelectedIndex();
    style = Font.PLAIN;
    switch (i) {
        case 0:
            style = Font.PLAIN;
            break;
        case 1:
            style = Font.BOLD;
            break;
        case 2:
            style = Font.ITALIC;
            break;
        case 3:
            style = Font.BOLD | Font.ITALIC;
            break;
    }
    styleChanged = style != oldStyle;


    fontFamily = tfFont.getText();
    if (sizeChanged || styleChanged) {
        this.errorMsg = errorMsg;
        updateFontList();
    } else {
        this.errorMsg = errorMsg;
    }
    // TMP FontEditor.this.setValue (new Font (tfFont.getText (), ii, size));
    font = new Font(fontFamily, style, size);
    invalidate();
    Component p = getParent();
    if (p != null) {
        p.validate();
    }
    repaint();
}
 
Example 20
private void makeComboBoxDropDownWider() {
	Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
	BasicComboPopup popup = (BasicComboPopup) child;
	Insets borderInsets = popup.getBorder().getBorderInsets(popup);
	JList<?> list = popup.getList();
	Dimension preferred = list.getPreferredSize();

	IntUnaryOperator extractWidth = i -> comboBox.getRenderer()
			.getListCellRendererComponent(list, model.getElementAt(i), i, false, false)
			.getPreferredSize().width + 3;
	preferred.width = IntStream.range(0, model.getSize()).map(extractWidth)
			.reduce(comboBox.getWidth() - borderInsets.left - borderInsets.right, Integer::max);

	int itemCount = comboBox.getItemCount();
	int rowHeight = 10;
	if (itemCount > 0) {
		rowHeight = preferred.height / itemCount;
	}
	int maxHeight = comboBox.getMaximumRowCount() * rowHeight;
	preferred.height = Math.min(preferred.height, maxHeight);

	Container c = SwingUtilities.getAncestorOfClass(JScrollPane.class, list);
	JScrollPane scrollPane = (JScrollPane) c;

	scrollPane.setPreferredSize(preferred);
	scrollPane.setMaximumSize(preferred);

	if (popup.isShowing()) { // 
		// a little trick to fire Popup.showPopup method that takes care of correct display
		popup.setLocation(comboBox.getLocationOnScreen().x, popup.getLocationOnScreen().y - 1);
	}

	Dimension popupSize = new Dimension();
	popupSize.width = preferred.width + borderInsets.left + borderInsets.right;
	popupSize.height = preferred.height + borderInsets.top + borderInsets.bottom;
	Component parent = popup.getParent();
	if (parent != null) {
		parent.setSize(popupSize);
		parent.validate();
		parent.repaint();
	}
}