List of utility methods to do Graphics Draw Gradient
void | DrawGradient(Graphics g, int x, int y, int width, int height, Color color1, Color color2) Draws a gradient Graphics2D graphics2D = (Graphics2D) g; GradientPaint gradient = new GradientPaint(width / 2, y, color1, width / 2, height / 2, color2); Rectangle2D rect = new Rectangle2D.Double(x, y, width, height / 2); graphics2D.setPaint(gradient); graphics2D.fill(rect); GradientPaint gradient = new GradientPaint(width / 2, height / 2, color2, width / 2, height, color1); Rectangle2D rect = new Rectangle2D.Double(x, y + height / 2, width, height); graphics2D.setPaint(gradient); graphics2D.fill(rect); |
SwingWorker | linearGradient(final JComponent comp, final Color col, final int step, final int sleepTime) linear Gradient final Color cCol = comp.getBackground(); SwingWorker<Void, Void> colorThread = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { int cR = cCol.getRed(); int cG = cCol.getGreen(); int cB = cCol.getBlue(); int R = col.getRed(); ... |
void | paintGradient(Graphics g, JComponent comp, Color color1, Color color2) Paints a top to bottom gradient fill over the component bounds from color1 to color2. GradientPaint paint = new GradientPaint(0, 0, color1, 0, comp.getHeight(), color2, true);
Graphics2D g2 = (Graphics2D) g;
Paint oldPaint = g2.getPaint();
g2.setPaint(paint);
g2.fillRect(0, 0, comp.getWidth(), comp.getHeight());
g2.setPaint(oldPaint);
|
void | paintGradientSelection(Color topLineColor, Color bottomLineColor, Color topGradientColor, Color bottomGradientColor, Graphics2D graphics2D, int width, int height) paint Gradient Selection GradientPaint paint = new GradientPaint(0, 1, topGradientColor, 0, height - 2, bottomGradientColor);
graphics2D.setPaint(paint);
graphics2D.fillRect(0, 0, width, height);
graphics2D.setColor(topLineColor);
graphics2D.drawLine(0, 0, width, 0);
graphics2D.setColor(bottomLineColor);
graphics2D.drawLine(0, height - 1, width, height - 1);
|
void | paintHorizontalGradient2D(Graphics2D g, int x, int y, int w, int h, float g1, float g2, Color c1, Color c2, Color c3, int[][] mask) Paints a horizontal gradient using Graphics2D functionality. GradientPaint p1 = new GradientPaint(x, y, c1, x + w * g1, y, c2); g.setPaint(p1); g.fillRect(x, y, (int) (w * (g1 + g2)), h); GradientPaint p2 = new GradientPaint(x + (w * (g1 + g2)), y, c2, x + w, y, c3); g.setPaint(p2); g.fillRect((int) (x + (w * (g1 + g2))), y, (int) (w * (1. - (g1 + g2))), h); |
void | paintListGradientSelection(Graphics2D graphics2D, Component component, int width, int height) paint List Gradient Selection paintGradientSelection(LIST_TOP_LINE_COLOR, LIST_BOTTOM_GRADIENT_COLOR, LIST_TOP_GRADIENT_COLOR, LIST_BOTTOM_GRADIENT_COLOR, graphics2D, width, height); |
void | paintMacGradientFill(Graphics2D g, Rectangle rect, Color brightC, Color darkC) Fills given rectangle using top-down gradient fill of specified colors Paint oldPaint = g.getPaint(); if (null == brightC) brightC = Color.gray; if (null == darkC) darkC = Color.gray; g.setPaint(new GradientPaint(rect.x, rect.y, brightC, rect.x, rect.y + rect.height / 2, darkC)); g.fillRect(rect.x, rect.y, rect.width, rect.height); g.setPaint(oldPaint); ... |
void | paintVerticalGradient2D(Graphics2D g, int x, int y, int w, int h, float g1, float g2, Color c1, Color c2, Color c3, int[][] mask) paint Vertical Gradient D GradientPaint p1 = new GradientPaint(x, y, c1, x, y + h * g1, c2); g.setPaint(p1); g.fillRect(x, y, w, (int) (h * (g1 + g2))); GradientPaint p2 = new GradientPaint(x, y + (h * (g1 + g2)), c2, x, y + h, c3); g.setPaint(p2); g.fillRect(x, (int) (y + (h * (g1 + g2))), w, (int) (h * (1. - (g1 + g2)))); |