List of usage examples for java.awt GradientPaint GradientPaint
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; GradientPaint p = new GradientPaint(0, 0, Color.white, getWidth(), getHeight(), Color.gray); g2d.setPaint(p);//from ww w .j a v a 2 s. co m g2d.fillRect(0, 0, getWidth(), getHeight()); }
From source file:StringGraidentPaint.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; int w = getSize().width; int h = getSize().height; g2D.setFont(font);//from w w w . j av a 2 s . c om GradientPaint gp = new GradientPaint(30.0f, 50.0f, Color.blue, fontMetrics.stringWidth("Hello!"), fontMetrics.getHeight(), Color.red); g2D.setPaint(gp); g2D.drawString("Hello!", 20, 200); }
From source file:GradientPaintEllipse.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x = 5;/*from w w w . j ava 2s . co m*/ int y = 7; // fill Ellipse2D.Double GradientPaint redtowhite = new GradientPaint(x, y, Color.red, 200, y, Color.white); g2.setPaint(redtowhite); g2.fill(new Ellipse2D.Double(x, y, 200, 200)); g2.setPaint(Color.black); g2.drawString("Filled Ellipse2D", x, 250); }
From source file:GradientPaintDemo2D.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.gray);//w ww . jav a2 s . c om int x = 5; int y = 7; // fill RoundRectangle2D.Double GradientPaint redtowhite = new GradientPaint(x, y, Color.red, 200, y, Color.blue); g2.setPaint(redtowhite); g2.fill(new RoundRectangle2D.Double(x, y, 200, 200, 10, 10)); g2.setPaint(Color.black); g2.drawString("Filled RoundRectangle2D", x, 250); }
From source file:Utils.java
public static BufferedImage createGradientMask(int width, int height, int orientation) { // algorithm derived from Romain Guy's blog BufferedImage gradient = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = gradient.createGraphics(); GradientPaint paint = new GradientPaint(0.0f, 0.0f, new Color(1.0f, 1.0f, 1.0f, 1.0f), orientation == SwingConstants.HORIZONTAL ? width : 0.0f, orientation == SwingConstants.VERTICAL ? height : 0.0f, new Color(1.0f, 1.0f, 1.0f, 0.0f)); g.setPaint(paint);// ww w. ja v a 2 s . com g.fill(new Rectangle2D.Double(0, 0, width, height)); g.dispose(); gradient.flush(); return gradient; }
From source file:Main.java
public static void smoothFillHorGradient(Graphics g, Color[] colors, int x, int y, int w, int h) { Graphics2D g2D = (Graphics2D) g; Paint savedPaint = g2D.getPaint(); int steps = colors.length; double dy = (double) h / (double) (steps - 1); int y1 = y;/*w w w.j a va 2 s. c o m*/ for (int i = 0; i < steps; i++) { int y2 = y + (int) Math.round((double) i * dy); if (i == (steps - 1)) { g2D.setPaint(null); g2D.setColor(colors[i]); g2D.fillRect(x, y1, w, y + h - y1); } else { g2D.setPaint(new GradientPaint(0, y1, colors[i], 0, y2, colors[i + 1])); g2D.fillRect(x, y1, w, y2 - y1); } y1 = y2; } g2D.setPaint(savedPaint); }
From source file:Test.java
public ApplicationWindow() { setBackground(new Color(0, 0, 0, 0)); this.setSize(200, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { @Override/* w ww . j a v a 2s. c o m*/ protected void paintComponent(Graphics gradient) { if (gradient instanceof Graphics2D) { final int Red = 150; final int Green = 150; final int Blue = 150; Paint paint = new GradientPaint(0.0f, 0.0f, new Color(Red, Green, Blue, 0), getWidth(), getHeight(), new Color(Red, Green, Blue, 255)); Graphics2D gradient2d = (Graphics2D) gradient; gradient2d.setPaint(paint); gradient2d.fillRect(0, 0, getWidth(), getHeight()); } } }; this.setContentPane(panel); }
From source file:TextureWithBufferedImage.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; Rectangle2D rec1, rec2, rec3, rec4, rec5; rec1 = new Rectangle2D.Float(25, 25, 75, 150); rec2 = new Rectangle2D.Float(125, 25, 10, 75); rec3 = new Rectangle2D.Float(75, 125, 125, 75); rec4 = new Rectangle2D.Float(25, 15, 12, 75); rec5 = new Rectangle2D.Float(15, 50, 15, 15); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1); g2D.setComposite(ac);/* w w w.j a v a2s . c o m*/ g2D.setStroke(new BasicStroke(5.0f)); g2D.draw(rec1); GradientPaint gp = new GradientPaint(125f, 25f, Color.yellow, 225f, 100f, Color.blue); g2D.setPaint(gp); g2D.fill(rec2); BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); Graphics2D big = bi.createGraphics(); big.setColor(Color.magenta); big.fillRect(0, 0, 5, 5); big.setColor(Color.black); big.drawLine(0, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); TexturePaint tp = new TexturePaint(bi, r); g2D.setPaint(tp); g2D.fill(rec3); g2D.setColor(Color.green); g2D.fill(rec4); g2D.setColor(Color.red); g2D.fill(rec5); }
From source file:org.jfree.chart.demo.GradientPaintTransformerDemo1.java
public static JPanel createDemoPanel() { JPanel jpanel = new JPanel(new GridLayout(2, 2)); jpanel.setPreferredSize(new Dimension(800, 600)); CategoryDataset categorydataset = createDataset(); JFreeChart jfreechart = createChart("Type: VERTICAL", categorydataset); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setDrawBarOutline(false); barrenderer.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); barrenderer.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); barrenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); ChartPanel chartpanel = new ChartPanel(jfreechart); jpanel.add(chartpanel);/*from w ww . j a v a 2 s . c o m*/ JFreeChart jfreechart1 = createChart("Type: HORIZONTAL", categorydataset); CategoryPlot categoryplot1 = (CategoryPlot) jfreechart1.getPlot(); BarRenderer barrenderer1 = (BarRenderer) categoryplot1.getRenderer(); barrenderer1.setDrawBarOutline(false); barrenderer1.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); barrenderer1.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); barrenderer1.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); ChartPanel chartpanel1 = new ChartPanel(jfreechart1); jpanel.add(chartpanel1); JFreeChart jfreechart2 = createChart("Type: CENTER_VERTICAL", categorydataset); CategoryPlot categoryplot2 = (CategoryPlot) jfreechart2.getPlot(); BarRenderer barrenderer2 = (BarRenderer) categoryplot2.getRenderer(); barrenderer2.setDrawBarOutline(false); barrenderer2.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); barrenderer2.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); barrenderer2.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL)); ChartPanel chartpanel2 = new ChartPanel(jfreechart2); jpanel.add(chartpanel2); JFreeChart jfreechart3 = createChart("Type: CENTER_HORIZONTAL", categorydataset); CategoryPlot categoryplot3 = (CategoryPlot) jfreechart3.getPlot(); BarRenderer barrenderer3 = (BarRenderer) categoryplot3.getRenderer(); barrenderer3.setDrawBarOutline(false); barrenderer3.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow)); barrenderer3.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green)); barrenderer3.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); ChartPanel chartpanel3 = new ChartPanel(jfreechart3); jpanel.add(chartpanel3); return jpanel; }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static void drawOldLinearGradientPaintTest(Graphics2D g2) { // top left/* w w w . j a v a2s .c o m*/ GradientPaint lgp = new GradientPaint(10, 30, Color.RED, 50, 30, Color.BLUE); g2.setPaint(lgp); g2.fill(new Rectangle2D.Double(10, 10, 40, 40)); // top right lgp = new GradientPaint(80, 10, Color.RED, 80, 50, Color.BLUE); g2.setPaint(lgp); g2.fill(new Rectangle2D.Double(60, 10, 40, 40)); // bottom left lgp = new GradientPaint(10, 100, Color.RED, 50, 60, Color.BLUE); g2.setPaint(lgp); g2.fill(new Rectangle2D.Double(10, 60, 40, 40)); // bottom right lgp = new GradientPaint(70, 70, Color.RED, 90, 90, Color.BLUE); g2.setPaint(lgp); g2.fill(new Rectangle2D.Double(60, 60, 40, 40)); }