Tabnine Logo
Color
Code IndexAdd Tabnine to your IDE (free)

How to use
Color
in
java.awt

Best Java code snippets using java.awt.Color (Showing top 20 results out of 17,343)

Refine searchRefine arrow

  • Window
  • JFrame
  • Container
  • Graphics
  • JComponent
  • Graphics2D
  • Component
origin: stackoverflow.com

Color c = new Color(-16726016, true);
 System.out.println(c.getRed());
 System.out.println(c.getGreen());
 System.out.println(c.getBlue());
 System.out.println(c.getAlpha());
origin: runelite/runelite

private int toColor(int height)
{
  // height seems to be between -2040 and 0, inclusive
  height = -height;
  // Convert to between 0 and 1
  float color = (float) height / MAX_HEIGHT;
  assert color >= 0.0f && color <= 1.0f;
  return new Color(color, color, color).getRGB();
}
origin: libgdx/libgdx

/** Convers a color to a string. */
static public String toString (Color color) {
  if (color == null) throw new IllegalArgumentException("color cannot be null.");
  String r = Integer.toHexString(color.getRed());
  if (r.length() == 1) r = "0" + r;
  String g = Integer.toHexString(color.getGreen());
  if (g.length() == 1) g = "0" + g;
  String b = Integer.toHexString(color.getBlue());
  if (b.length() == 1) b = "0" + b;
  return r + g + b;
}
origin: twosigma/beakerx

public Color(java.awt.Color awtColor) {
 this(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue(), awtColor.getAlpha());
}
 
origin: stackoverflow.com

private JFrame frame = new JFrame("sssssssss");
private JButton tip1Null = new JButton(" test button ");
  ((Graphics2D) g).setRenderingHint(
    RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setColor(color);
  g.drawRoundRect(x, y, width, height, MARGIN, MARGIN);
  final Color color1 = new Color(230, 255, 255, 0);
  final Color color2 = new Color(255, 230, 255, 64);
  final Color alphaColor = new Color(200, 200, 230, 64);
  final Color color3 = new Color(
    alphaColor.getRed(), alphaColor.getGreen(), alphaColor.getBlue(), 0);
  final Color color4 = new Color(
    alphaColor.getRed(), alphaColor.getGreen(), alphaColor.getBlue(), 64);
  super.paint(g, c);
  Graphics2D g2D = (Graphics2D) g;
  g2D.setPaint(gradient1);
  g2D.fill(rec1);
  paintText(g, b, b.getBounds(), b.getText());
  g.setColor(Color.red.brighter());
  g.fillRect(0, 0, b.getSize().width, b.getSize().height);
origin: stackoverflow.com

Graphics2D g2d = (Graphics2D) g.create();
g2d.setColor(new Color(0xFFAA00));
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(basicStroke);
g2d.drawRoundRect(3, 3, getWidth()-4, getHeight()-4, archH, archH);
setLayout(new GridBagLayout()); 
add(usrNameLabel, labCnst);
add(usrNameFeild, txtCnst);
comp.setFont(getFont().deriveFont(Font.BOLD, 13));
                            new Color[] { new Color(0x002AFF),
                            new Color(0x0CAAF9),
                            new Color(0x0CAAF9),
                            new Color(0x002AFF) });
    JFrame frame = new JFrame("Demo: LogIn Dialogue");
    frame.setSize(new Dimension(500, 300)); 
    MainContainer container = new MainContainer();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
origin: libgdx/libgdx

public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
  g = (Graphics2D)g.create();
  g.translate(xDistance, yDistance);
  g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), Math.round(opacity * 255)));
  g.fill(glyph.getShape());
  // Also shadow the outline, if one exists.
  for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) {
    Effect effect = (Effect)iter.next();
    if (effect instanceof OutlineEffect) {
      Composite composite = g.getComposite();
      g.setComposite(AlphaComposite.Src); // Prevent shadow and outline shadow alpha from combining.
      g.setStroke(((OutlineEffect)effect).getStroke());
      g.draw(glyph.getShape());
      g.setComposite(composite);
      break;
    }
  }
  g.dispose();
  if (blurKernelSize > 1 && blurKernelSize < NUM_KERNELS && blurPasses > 0) blur(image);
}
origin: stackoverflow.com

private int padding = 25;
private int labelPadding = 25;
private Color lineColor = new Color(44, 102, 230, 180);
private Color pointColor = new Color(100, 100, 100, 180);
private Color gridColor = new Color(200, 200, 200, 200);
private static final Stroke GRAPH_STROKE = new BasicStroke(2f);
private int pointWidth = 4;
  super.paintComponent(g);
  Graphics2D g2 = (Graphics2D) g;
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  double xScale = ((double) getWidth() - (2 * padding) - labelPadding) / (scores.size() - 1);
  double yScale = ((double) getHeight() - 2 * padding - labelPadding) / (getMaxScore() - getMinScore());
  g2.setColor(Color.WHITE);
  g2.fillRect(padding + labelPadding, padding, getWidth() - (2 * padding) - labelPadding, getHeight() - 2 * padding - labelPadding);
  g2.setColor(Color.BLACK);
      g2.drawString(yLabel, x0 - labelWidth - 5, y0 + (metrics.getHeight() / 2) - 3);
        g2.drawString(xLabel, x0 - labelWidth / 2, y0 + metrics.getHeight() + 3);
  invalidate();
  this.repaint();
origin: stackoverflow.com

+ "The effect we want is a multi-line label.";
JFrame f = new JFrame("Label Render Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textLabel.setSize(textLabel.getPreferredSize());
Dimension d = textLabel.getPreferredSize();
BufferedImage bi = new BufferedImage(
  d.width,
  BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics();
g.setColor(new Color(255, 255, 255, 128));
g.fillRoundRect(
  0,
  0,
JLabel imageLabel = new JLabel(ii);
f.getContentPane().add(imageLabel);
f.pack();
f.setLocationByPlatform(true);
f.setVisible(true);
origin: stackoverflow.com

private static final int BORDER_GAP = 30;
private static final Color GRAPH_COLOR = Color.green;
private static final Color GRAPH_POINT_COLOR = new Color(150, 50, 50, 180);
private static final Stroke GRAPH_STROKE = new BasicStroke(3f);
private static final int GRAPH_POINT_WIDTH = 12;
 super.paintComponent(g);
 Graphics2D g2 = (Graphics2D)g;
 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 double xScale = ((double) getWidth() - 2 * BORDER_GAP) / (scores.size() - 1);
 double yScale = ((double) getHeight() - 2 * BORDER_GAP) / (MAX_SCORE - 1);
 g2.drawLine(BORDER_GAP, getHeight() - BORDER_GAP, BORDER_GAP, BORDER_GAP);
 g2.drawLine(BORDER_GAP, getHeight() - BORDER_GAP, getWidth() - BORDER_GAP, getHeight() - BORDER_GAP);
   int y0 = getHeight() - (((i + 1) * (getHeight() - BORDER_GAP * 2)) / Y_HATCH_CNT + BORDER_GAP);
   int y1 = y0;
   g2.drawLine(x0, y0, x1, y1);
 Stroke oldStroke = g2.getStroke();
 g2.setColor(GRAPH_COLOR);
 g2.setStroke(GRAPH_STROKE);
 for (int i = 0; i < graphPoints.size() - 1; i++) {
   int x1 = graphPoints.get(i).x;
origin: runelite/runelite

  private void renderPoly(Graphics2D graphics, Color color, Polygon polygon)
  {
    if (polygon != null)
    {
      graphics.setColor(color);
      graphics.setStroke(new BasicStroke(2));
      graphics.draw(polygon);
      graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20));
      graphics.fill(polygon);
    }
  }
}
origin: stackoverflow.com

  this.setPreferredSize(new Dimension(W, H));
  timer.start();
  JFrame f = new JFrame();
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.setBackground(new Color(0f, 0f, 0f, 0.3f));
  f.setUndecorated(true);
  f.add(new Translucent());
  f.pack();
  f.setLocationRelativeTo(null);
  f.setVisible(true);
public void actionPerformed(ActionEvent e) {
  now.setTime(System.currentTimeMillis());
  this.repaint();
origin: linlinjava/litemall

private void drawTextInImg(BufferedImage baseImage, String textToWrite, int x, int y) {
  Graphics2D g2D = (Graphics2D) baseImage.getGraphics();
  g2D.setColor(new Color(167, 136, 69));
  //TODO 注意,这里的字体必须安装在服务器上
  g2D.setFont(new Font("Microsoft YaHei", Font.PLAIN, 28));
  g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2D.drawString(textToWrite, x, y);
  g2D.dispose();
}
origin: stackoverflow.com

final BufferedImage dietered = floydSteinbergDithering(ImageIO.read(new URL("http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png"))).getSubimage(100, 100, 300, 300);
JFrame frame = new JFrame("Test");
frame.setLayout(new GridLayout(1, 2));
frame.add(new JComponent() {
 @Override
 protected void paintComponent(Graphics g) {
 Color color = new Color(c);
 this.r = color.getRed();
 this.g = color.getGreen();
 this.b = color.getBlue();
 return new Color(clamp(r), clamp(g), clamp(b));
origin: stackoverflow.com

constraints.fill = GridBagConstraints.BOTH;
JLabel l = new JLabel("You have got 2 new Messages.");
panel.add(l, constraints);
constraints.gridx++;
constraints.weightx = 0f;
    dialog.dispose();
    new float[]{0f, 0.3f, 1f}, new Color[]{new Color(0.8f, 0.8f, 1f),
      new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f)});
dialog.setContentPane(panel);
dialog.setVisible(true);
  setOpaque(true);
protected void paintComponent(final Graphics g) {
  final Graphics2D g2d = (Graphics2D) g;
  g2d.setPaint(lpg);
  g2d.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
  g2d.setColor(Color.BLACK);
  g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
origin: stackoverflow.com

repaint();
repaint();
super.paintComponent(g);
for (Line line : lines) {
  g.setColor(line.color);
  g.drawLine(line.x1, line.y1, line.x2, line.y2);
    int y1 = (int) (Math.random()*200);
    int y2 = (int) (Math.random()*200);
    Color randomColor = new Color((float)Math.random(), (float)Math.random(), (float)Math.random());
    comp.addLine(x1, y1, x2, y2, randomColor);
testFrame.pack();
testFrame.setVisible(true);
origin: stackoverflow.com

      "<div style='width: 100%; height: 100%; " +
      "background-color: #" +
      Integer.toHexString(color.getRed()) +
      Integer.toHexString(color.getGreen()) +
      Integer.toHexString(color.getBlue()) +
      ";'>" +
      value.toString() +
ta.setFocusable(false);
return ta;
JPanel fontTable = new JPanel(new BorderLayout(3, 1));
fontTable.setFocusable(true);
JPanel fontNameCol = new JPanel(new GridLayout(0, 1, 2, 2));
JPanel fontExampleCol = new JPanel(new GridLayout(0, 1, 2, 2));
fontTable.add(fontNameCol, BorderLayout.WEST);
fontTable.add(fontExampleCol, BorderLayout.CENTER);
for (int ii = 0; ii < fonts.length; ii++) {
  fontNameCol.add(new JLabel(fonts[ii]));
origin: stackoverflow.com

protected void paintComponent(Graphics g) {
  if (getModel().isPressed()) {
    g.setColor(pressedBackgroundColor);
  } else if (getModel().isRollover()) {
    g.setColor(hoverBackgroundColor);
  } else {
    g.setColor(getBackground());
  g.fillRect(0, 0, getWidth(), getHeight());
  super.paintComponent(g);
JFrame frame = new JFrame("Test button");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final MyButton btnSave = new MyButton("Save");
btnSave.setForeground(new Color(0, 135, 200).brighter());
btnSave.setHorizontalTextPosition(SwingConstants.CENTER);
btnSave.setBorder(null);
btnSave.setBackground(new Color(3, 59, 90));
btnSave.setHoverBackgroundColor(new Color(3, 59, 90).brighter());
btnSave.setPressedBackgroundColor(Color.PINK);
frame.add(btnSave);
frame.setSize(200, 200);
frame.setVisible(true);
origin: stackoverflow.com

  JFrame f = new JFrame();
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  jtp.setPreferredSize(new Dimension(400, 200));
  createTab("Reds", Color.RED);
  createTab("Greens", Color.GREEN);
  createTab("Blues", Color.BLUE);
  f.add(jtp, BorderLayout.CENTER);
  f.pack();
  f.setVisible(true);
this.parent = parent;
this.icon = icon;
this.mask = icon.color.getRGB();
this.setBackground(icon.color);
label.setForeground(icon.color);
this.add(label);
timer.start();
this.setBackground(new Color(rnd.nextInt() & mask));
this.icon.update(count += rnd.nextInt(8));
this.parent.repaint();
g.setColor(color);
g.fillRect(x, y, w, H);
origin: stackoverflow.com

 window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 window.setLocationByPlatform(true);
 window.setVisible(true);
private Color pInterfaceColour = new Color(255, 245, 62);
protected int iDegreeWhite = 180;
protected int iDegreeBlack = 0;
 setSize(iWidth, iHeight);
 getContentPane().setBackground(pInterfaceColour);
 pGradientPane = new JPanel() {
   private static final long serialVersionUID = 1L;
    pGraphicsGradientRender.setRenderingHint(
       RenderingHints.KEY_ANTIALIASING,
       RenderingHints.VALUE_ANTIALIAS_ON);
    GradientPaint pGradient = new GradientPaint(0, 0, new Color(255,
       255, 255, iDegreeWhite), 0, getHeight(), new Color(0, 0, 0,
       iDegreeBlack));
    pGraphicsGradientRender.setPaint(pGradient);
    pGraphicsGradientRender.fillRect(0, 0, getWidth(), getHeight());
    super.paintComponent(pGraphics);
 pGradientPane.setPreferredSize(new Dimension(iWidth - 16, iHeight - 62));
 add(pGradientPane);
java.awtColor

Javadoc

The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary color spaces identified by a ColorSpace. Every color has an implicit alpha value of 1.0 or an explicit one provided in the constructor. The alpha value defines the transparency of a color and can be represented by a float value in the range 0.0 - 1.0 or 0 - 255. An alpha value of 1.0 or 255 means that the color is completely opaque and an alpha value of 0 or 0.0 means that the color is completely transparent. When constructing a Color with an explicit alpha or getting the color/alpha components of a Color, the color components are never premultiplied by the alpha component.

The default color space for the Java 2D(tm) API is sRGB, a proposed standard RGB color space. For further information on sRGB, see http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html .

Most used methods

  • <init>
  • getRed
    Returns the red component in the range 0-255 in the default sRGB space.
  • getBlue
    Returns the blue component in the range 0-255 in the default sRGB space.
  • getGreen
    Returns the green component in the range 0-255 in the default sRGB space.
  • getRGB
    Returns the RGB value representing the color in the default sRGB ColorModel. (Bits 24-31 are alpha,
  • getAlpha
  • equals
    Determines whether another object is equal to thisColor. The result is true if and only if the argum
  • darker
    Creates a new Color that is a darker version of thisColor. This method applies an arbitrary scale fa
  • decode
    Converts a String to an integer and returns the specified opaque Color. This method handles string f
  • brighter
    Creates a new Color that is a brighter version of thisColor. This method applies an arbitrary scale
  • RGBtoHSB
    Converts the components of a color, as specified by the default RGB model, to an equivalent set of v
  • getHSBColor
    Creates a Color object based on the specified values for the HSB color model. The s and b component
  • RGBtoHSB,
  • getHSBColor,
  • HSBtoRGB,
  • hashCode,
  • getRGBComponents,
  • getRGBColorComponents,
  • toString,
  • getColorComponents,
  • getComponents,
  • getColorSpace

Popular in Java

  • Reactive rest calls using spring rest template
  • setRequestProperty (URLConnection)
  • setContentView (Activity)
  • startActivity (Activity)
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • JComboBox (javax.swing)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now