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

The following examples show how to use java.awt.Component#repaint() . 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
@Override
protected void forwardUpdate(DocumentEvent.ElementChange ec,
        DocumentEvent e, Shape a, ViewFactory f)
{
    boolean wasValid = isLayoutValid(majorAxis);
    super.forwardUpdate(ec, e, a, f);

    // determine if a repaint is needed
    if (wasValid && (!isLayoutValid(majorAxis)))
    {
        // Repaint is needed because one of the tiled children
        // have changed their span along the major axis. If there
        // is a hosting component and an allocated shape we repaint.
        Component c = getContainer();
        if ((a != null) && (c != null))
        {
            Rectangle alloc = getInsideAllocation(a);
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
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
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 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: ET_Redux   File: ValueModelClump.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param g2d
 */
public void paint ( Graphics2D g2d ) {

    RenderingHints rh = g2d.getRenderingHints();
    rh.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
    rh.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
    g2d.setRenderingHints( rh );

    g2d.setColor( Color.black );
    DrawBounds( g2d );

    //  paint valuesliders
    for (Component vms : getComponents()) {
        if ( vms instanceof JPanel ) {
            vms.repaint();
        }
    }

}
 
Example 8
Source Project: Bytecoder   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 9
public static void main(final String[] args) throws AWTException {
    final Frame frame = new Frame();
    final Component label = new PaintNativeOnUpdate();
    frame.setBackground(Color.RED);
    frame.add(label);
    frame.setSize(300, 300);
    frame.setUndecorated(true);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    sleep();
    label.repaint();// first paint
    sleep();
    label.repaint();// incremental paint
    sleep();

    Robot robot = new Robot();
    robot.setAutoDelay(50);
    Point point = label.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
                                      point.y + label.getHeight() / 2);
    if (!color.equals(Color.GREEN)) {
        System.err.println("Expected color = " + Color.GREEN);
        System.err.println("Actual color = " + color);
        throw new RuntimeException();
    }
    frame.dispose();
}
 
Example 10
private static void animateComponent(final Component comp) {
    Thread t = new Thread(new Runnable() {
        public void run() {
            do {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException ex) {}
                comp.repaint();
            } while (!done);
        }
    });
    t.start();
}
 
Example 11
Source Project: jdk8u-jdk   File: TSFrame.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void animateComponent(final Component comp) {
    Thread t = new Thread(new Runnable() {
        public void run() {
            do {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException ex) {}
                comp.repaint();
            } while (!done);
        }
    });
    t.start();
}
 
Example 12
private static void animateComponent(final Component comp) {
    Thread t = new Thread(new Runnable() {
        public void run() {
            do {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException ex) {}
                comp.repaint();
            } while (!done);
        }
    });
    t.start();
}
 
Example 13
private static void animateComponent(final Component comp) {
    Thread t = new Thread(new Runnable() {
        public void run() {
            do {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException ex) {}
                comp.repaint();
            } while (!done);
        }
    });
    t.start();
}
 
Example 14
Source Project: jdk8u_jdk   File: TSFrame.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void animateComponent(final Component comp) {
    Thread t = new Thread(new Runnable() {
        public void run() {
            do {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException ex) {}
                comp.repaint();
            } while (!done);
        }
    });
    t.start();
}
 
Example 15
Source Project: Briss-2.0   File: BrissGUI.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void componentResized(ComponentEvent e) {
    previewPanel.revalidate();
    for (Component component : previewPanel.getComponents()) {
        component.repaint();
    }
}
 
Example 16
private static void animateComponent(final Component comp) {
    Thread t = new Thread(new Runnable() {
        public void run() {
            do {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException ex) {}
                comp.repaint();
            } while (!done);
        }
    });
    t.start();
}
 
Example 17
Source Project: netbeans   File: DropdownButton.java    License: Apache License 2.0 5 votes vote down vote up
public void setText(String text) {
    if (button != null) {
        String _text = button.getText();
        button.setText(text);
        
        Component parent = getParent();
        if (!Objects.equals(text, _text) && parent != null) {
            parent.invalidate();
            parent.revalidate();
            parent.repaint();
        }
    }
}
 
Example 18
@Override
public void focusGained(FocusEvent e) {
	Component c = (Component) e.getSource();
	c.repaint();
}
 
Example 19
Source Project: netbeans   File: GapBoxView.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Process pending repaint requests from children.
 * <br>
 * Children are guaranteed to be non-null once this method gets called.
 */
protected void processRepaint(ViewLayoutState.Parent lsParent) {
    if (lsParent != null) { // parent view is ViewLayoutState.Parent
        int firstRepaintChildIndex = children.getFirstRepaintChildIndex();
        double majorAxisOffset = children.getMajorAxisOffset(firstRepaintChildIndex);
        double repaintMajorOffset;
        double repaintMajorSpan;
        float repaintMinorOffset;
        float repaintMinorSpan;
        if (isRepaintTillEnd()
            || firstRepaintChildIndex >= getViewCount() // bit strange but possible after last child remove
        ) {
            if (isMajorAxesOrthogonal()) {
                repaintMajorOffset = 0;
                repaintMajorSpan = 0; // till end of view's span in parent
                repaintMinorOffset = (float)majorAxisOffset;
                repaintMinorSpan = 0; // till parent view minor span end

            } else { // major axes equal
                repaintMajorOffset = majorAxisOffset;
                repaintMajorSpan = 0; // till end of view's span in parent
                repaintMinorOffset = 0;
                repaintMinorSpan = 0; // till parent view minor span end
            }

        } else { // repainting just single child that did not change major axis span
            double majorAxisSpan = getChild(firstRepaintChildIndex).getLayoutMajorAxisPreferredSpan();
            if (isMajorAxesOrthogonal()) {
                repaintMajorOffset = 0;
                repaintMajorSpan = 0; // till end of view's span in parent
                repaintMinorOffset = (float)majorAxisOffset;
                repaintMinorSpan = (float)majorAxisSpan;

            } else { // major axes equal
                repaintMajorOffset = majorAxisOffset;
                repaintMajorSpan = majorAxisSpan;
                repaintMinorOffset = 0;
                repaintMinorSpan = 0; // till parent view minor span end
            }
        }
        
        lsParent.repaint(this, repaintMajorOffset, repaintMajorSpan,
            repaintMinorOffset, repaintMinorSpan);
        
    } else { // do not know allocation here => repaint whole component
        Component c = getContainer();
        if (c != null) {
            c.repaint();
        }
    }
}
 
Example 20
public void repaint() {
    for (Component c : getComponentsToRemove()) {
        c.repaint();
    }
}