List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:XORRectangles.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // using white as the XOR color. g2.setXORMode(Color.white);// w ww . j a v a2 s.c om // Paint a red rectangle. Rectangle2D r = new Rectangle2D.Double(50, 50, 150, 100); g2.setPaint(Color.red); g2.fill(r); g2.transform(AffineTransform.getTranslateInstance(25, 25)); // Draw a blue rectangle. g2.setPaint(Color.blue); g2.fill(r); }
From source file:Main.java
public void paint(Graphics g) { int width = getWidth(); int height = getHeight(); // Create the gradient paint GradientPaint paint = new GradientPaint(0, 0, start, width, height, end, true); // we need to cast to Graphics2D for this operation Graphics2D g2d = (Graphics2D) g; // save the old paint Paint oldPaint = g2d.getPaint(); // set the paint to use for this operation g2d.setPaint(paint); // fill the background using the paint g2d.fillRect(0, 0, width, height);//w w w . j a v a2 s .c om // restore the original paint g2d.setPaint(oldPaint); super.paint(g); }
From source file:FilledArc.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x = 5;//w w w . j av a 2s.com int y = 7; // fill Arc2D g2.setPaint(Color.red); g2.fill(new Arc2D.Double(x, y, 200, 200, 90, 135, Arc2D.OPEN)); g2.setPaint(Color.black); g2.drawString("Filled Arc2D", x, 250); }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.heatmap.HeatMapImgGenerator.java
public String generateHeatmap(String[] rows, String[] columns, String[][] data) { JPanel heatmapPanelLayout = new JPanel(); heatmapPanelLayout.setLayout(null);// ww w . j a v a 2 s . c o m heatmapPanelLayout.setVisible(true); int width = (columns.length + 1) * 50; int height = (rows.length + 1) * 50; heatmapPanelLayout.setSize(width, height); JPanel cornerCell = initCell("#ffffff", 0, 0); int x = 50; int y = 0; heatmapPanelLayout.add(cornerCell); for (String headerCell : columns) { JPanel cell = initCell(headerCell, x, y); x += 50; heatmapPanelLayout.add(cell); } y = 50; for (String headerCell : rows) { JPanel cell = initCell(headerCell, 0, y); y += 50; heatmapPanelLayout.add(cell); } x = 50; y = 50; for (String[] row : data) { for (String color : row) { JPanel cell = initCell(color, x, y); heatmapPanelLayout.add(cell); x += 50; } x = 50; y += 50; } BufferedImage image = new BufferedImage(width + 10, height + 10, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setPaint(Color.WHITE); graphics.setBackground(Color.WHITE); heatmapPanelLayout.paint(graphics); byte[] imageData = null; try { ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f)); imageData = in.encode(image); } catch (Exception e) { System.out.println(e.getLocalizedMessage()); } String base64 = Base64.encodeBytes(imageData); base64 = "data:image/png;base64," + base64; return base64; }
From source file:Hypnosis1.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Shape s = createShape();//ww w .java2s .c om g2.setPaint(paint); g2.fill(s); g2.setPaint(Color.white); g2.draw(s); }
From source file:probe.com.model.util.vaadintoimageutil.Convertor.java
public String toImage(int height, int width, JComponent component) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setPaint(Color.WHITE); component.paint(graphics);/*from w w w . j a va 2 s .co m*/ // super.paint(graphics); byte[] imageData = null; try { imageData = in.encode(image); } catch (Exception e) { System.out.println(e.getLocalizedMessage()); } String base64 = Base64.encodeBytes(imageData); base64 = "data:image/png;base64," + base64; return base64; }
From source file:com.anrisoftware.prefdialog.miscswing.lists.RubberBandingList.java
private void drawSelectionRubberBand(Graphics2D g) { g.setPaint(getSelectionBackground()); g.draw(rubberBand);/* w w w . j a v a 2s .co m*/ g.setComposite(ALPHA); g.setPaint(selectionColor); g.fill(rubberBand); }
From source file:CompositeTest.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gImage = image.createGraphics(); gImage.setPaint(Color.red); gImage.fill(shape1);//from w w w .j a va 2s . c om AlphaComposite composite = AlphaComposite.getInstance(rule, alpha); gImage.setComposite(composite); gImage.setPaint(Color.blue); gImage.fill(shape2); g2.drawImage(image, null, 0, 0); }
From source file:SVGJUnitTest.java
public void paint(Graphics2D g2d) { g2d.setPaint(Color.red); g2d.fill(new Rectangle(10, 10, 100, 100)); }
From source file:SVGJUnitTest.java
public void paint2(Graphics2D g2d) { g2d.setPaint(Color.green); g2d.fill(new Rectangle(90, 90, 100, 100)); }