Example usage for java.awt Color Color

List of usage examples for java.awt Color Color

Introduction

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

Prototype

public Color(ColorSpace cspace, float[] components, float alpha) 

Source Link

Document

Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.

Usage

From source file:Main.java

public static void errorLabel(JLabel label) {
    label.setForeground(new Color(192, 0, 0));
    italicBoldLabel(label);
}

From source file:Main.java

/**
 * @param color//from  w  w w . j  av  a 2 s .  c o  m
 * @param factor
 * @return a new color, darker than the one passed as argument by a percentage factor
 *
 * <br>author Cyril Gambis  - [Mar 17, 2005]
 */
public static Color darker(Color color, double factor) {
    return new Color(Math.max((int) (color.getRed() * factor), 0),
            Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0));
}

From source file:Main.java

public static Color averageColor(Color c1, Color c2) {
    return new Color((c1.getRed() + c2.getRed()) / 2, (c1.getGreen() + c2.getGreen()) / 2,
            (c1.getBlue() + c2.getBlue()) / 2);
}

From source file:Main.java

/**
 * Retrieve and transform the property value into a Color.
 * @param name The property name/*w ww.  j  a va2 s  . co m*/
 * @return The corresponding color
 */
public static Color asColor(String color) {
    if (color != null) {
        String[] rgb = color.split(",");
        if (rgb.length == 3) {
            try {
                return new Color(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}

From source file:Main.java

public static JLabel modifyLabelFont(JLabel label, int style, int delta) {
    Font font = label.getFont();//from ww w .  j av  a  2  s.co m
    label.setFont(font.deriveFont(style, font.getSize() + delta));
    label.setForeground(new Color(140, 140, 140));
    return label;
}

From source file:Main.java

/**
 * Returns a "warning"-colored panel with given message.
 * //from  w  w  w.ja  v  a  2s.com
 * @param context
 * @param message
 * @return
 */
public static JPanel constructWarningPanel(String message) {
    JPanel p = new JPanel();
    JLabel l = new JLabel(message);

    // "magical" color
    p.setBackground(new Color(240, 40, 70));

    p.add(l);
    return p;
}

From source file:Main.java

public static Color darken(Color c, int r, int g, int b) {
    int or = c.getRed(), og = c.getGreen(), ob = c.getBlue();
    or -= r;//from   w w w.j  a  v  a 2s . com
    og -= g;
    ob -= b;
    or = or < 0 ? 0 : or;
    or = or > 255 ? 255 : or;
    og = og < 0 ? 0 : og;
    og = og > 255 ? 255 : og;
    ob = ob < 0 ? 0 : ob;
    ob = ob > 255 ? 255 : ob;
    return new Color(or, og, ob);
}

From source file:Main.java

/**
 * Adds a one pixel border of random color to this and all panels contained in this panel's
 * child hierarchy.//from w  w  w  .j av  a 2 s  . c  om
 */
public static void addDebugBorders(JPanel panel) {
    Color bcolor = new Color(_rando.nextInt(256), _rando.nextInt(256), _rando.nextInt(256));
    panel.setBorder(BorderFactory.createLineBorder(bcolor));

    for (int ii = 0; ii < panel.getComponentCount(); ii++) {
        Object child = panel.getComponent(ii);
        if (child instanceof JPanel) {
            addDebugBorders((JPanel) child);
        }
    }
}

From source file:Main.java

public static void setTheme() {
    final Color color = new Color(85, 142, 119);
    final Color colorBackground = new Color(247, 247, 247);
    Image error_dialog_icon = new ImageIcon("/images/error_dialog.png").getImage();

    UIManager.getLookAndFeelDefaults().put("nimbusOrange", color);
    UIManager.getLookAndFeelDefaults().put("control", colorBackground);

    UIManager.getLookAndFeelDefaults().put("OptionPane.errorIcon", error_dialog_icon);
    UIManager.getLookAndFeelDefaults().put("OptionPane.background", colorBackground);

    UIManager.getLookAndFeelDefaults().put("Panel.background", new Color(245, 245, 245));
    UIManager.put("Table.background", new Color(250, 250, 250));
    //        UIManager.put("Table.alternateRowColor", new Color(159,203,64));
}

From source file:Main.java

public static Color getRandColor(int threashold) {
    if (threashold < 0 || threashold > 255)
        throw new IllegalArgumentException("Threashold is not between 0 and 255");
    int secondOperand = 255 - threashold;
    return new Color((int) (Math.random() * secondOperand) + threashold,
            (int) (Math.random() * secondOperand) + threashold,
            (int) (Math.random() * secondOperand) + threashold);
}