Example usage for java.awt LinearGradientPaint LinearGradientPaint

List of usage examples for java.awt LinearGradientPaint LinearGradientPaint

Introduction

In this page you can find the example usage for java.awt LinearGradientPaint LinearGradientPaint.

Prototype

public LinearGradientPaint(float startX, float startY, float endX, float endY, float[] fractions,
        Color[] colors) 

Source Link

Document

Constructs a LinearGradientPaint with a default NO_CYCLE repeating method and SRGB color space.

Usage

From source file:org.jfree.graphics2d.demo.ImageTest.java

private static void drawLinearGradientPaintTest(Graphics2D g2) {
    // top left/*from  w w w  .j  a  va2 s  . c  o  m*/
    LinearGradientPaint lgp = new LinearGradientPaint(10, 30, 50, 30, new float[] { 0.0f, 1.0f },
            new Color[] { Color.RED, Color.BLUE });
    g2.setPaint(lgp);
    g2.fill(new Rectangle2D.Double(10, 10, 40, 40));

    // top right
    lgp = new LinearGradientPaint(80, 10, 80, 50, new float[] { 0.0f, 1.0f },
            new Color[] { Color.RED, Color.BLUE });
    g2.setPaint(lgp);
    g2.fill(new Rectangle2D.Double(60, 10, 40, 40));

    // bottom left
    lgp = new LinearGradientPaint(10, 100, 50, 60, new float[] { 0.0f, 1.0f },
            new Color[] { Color.RED, Color.BLUE });
    g2.setPaint(lgp);
    g2.fill(new Rectangle2D.Double(10, 60, 40, 40));

    // bottom right
    lgp = new LinearGradientPaint(70, 70, 90, 90, new float[] { 0.0f, 0.5f, 1.0f },
            new Color[] { Color.RED, Color.YELLOW, Color.BLUE }, CycleMethod.REPEAT);
    g2.setPaint(lgp);
    g2.fill(new Rectangle2D.Double(60, 60, 40, 40));

}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.CustomLegendGraphic.java

private static LinearGradientPaint getTranslatedLinearGradientPaint(LinearGradientPaint gradient,
        Point2D startPoint, Point2D endPoint, boolean vertical) {
    if (vertical) {
        return new LinearGradientPaint(0f, (float) startPoint.getY(), 0f, (float) endPoint.getY(),
                gradient.getFractions(), gradient.getColors());
    } else {/*w  w w .  j a v  a 2  s .  co m*/
        return new LinearGradientPaint((float) startPoint.getX(), 0f, (float) endPoint.getX(), 0f,
                gradient.getFractions(), gradient.getColors());
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.SmartLegendTitle.java

public static Paint transformLinearGradient(LinearGradientPaint paint, Shape target) {
    Rectangle2D bounds = target.getBounds2D();
    float left = (float) bounds.getMinX();
    float right = (float) bounds.getMaxX();
    LinearGradientPaint newPaint = new LinearGradientPaint(left, 0, right, 0, paint.getFractions(),
            paint.getColors());/*from ww w . j  a  v a  2  s  .co  m*/
    return newPaint;
}

From source file:be.ac.ua.comp.scarletnebula.gui.ServerCellRenderer.java

public JXPanel onRollOver(final JXPanel input) {
    final Color color1 = Colors.White.color(0.5f);
    final Color color2 = Colors.Black.color(0.8f);
    // Color color2 = Colors.Red.color(0.2f);

    final LinearGradientPaint gradientPaint = new LinearGradientPaint(0.0f, 0.0f, 250, 500,
            new float[] { 0.0f, 1.0f }, new Color[] { color1, color2 });
    final MattePainter mattePainter = new MattePainter(gradientPaint, true);

    input.setBackgroundPainter(new CompoundPainter<Object>(mattePainter, input.getBackgroundPainter()));
    return input;
}