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

The following examples show how to use java.awt.Component#validate() . 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: JLayeredPane.java    From jdk1.8-source-analysis with 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 2
Source File: JLayeredPane.java    From dragonwell8_jdk with GNU General Public License v2.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 3
Source File: JLayeredPane.java    From TencentKona-8 with GNU General Public License v2.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 4
Source File: JLayeredPane.java    From jdk8u60 with GNU General Public License v2.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 5
Source File: ComponentDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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
Source File: JLayeredPane.java    From openjdk-jdk8u with GNU General Public License v2.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 7
Source File: AnimationLayer.java    From netbeans with 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
Source File: JLayeredPane.java    From jdk8u-jdk with GNU General Public License v2.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 9
Source File: JLayeredPane.java    From hottub with GNU General Public License v2.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 10
Source File: JLayeredPane.java    From openjdk-jdk8u-backup with GNU General Public License v2.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 11
Source File: JLayeredPane.java    From Java8CN with 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
Source File: JLayeredPane.java    From openjdk-jdk9 with GNU General Public License v2.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 13
Source File: JLayeredPane.java    From jdk8u-jdk with GNU General Public License v2.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 14
Source File: PaddingInfo.java    From pumpernickel with 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 15
Source File: FindTopComponent.java    From constellation with 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 16
Source File: WindowUtils.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 File: BasicGridUI.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
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 18
Source File: FontPanel.java    From netbeans with 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 19
Source File: AbstractSuggestionBoxValueCellEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
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();
	}
}
 
Example 20
Source File: JFrame_Main.java    From MobyDroid with 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();
    }
}