List of usage examples for java.awt Color RED
Color RED
To view the source code for java.awt Color RED.
Click Source Link
From source file:Main.java
public Main() { JFrame frame = new JFrame(); JPanel container = new JPanel(); container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS)); CustomPanel customPanel1 = new CustomPanel(Color.blue); CustomPanel customPanel2 = new CustomPanel(Color.red); CustomPanel customPanel3 = new CustomPanel(Color.green); container.add(customPanel1);//from w ww. j a v a 2 s.c o m container.add(customPanel2); container.add(customPanel3); frame.getContentPane().add(container); frame.pack(); frame.setVisible(true); }
From source file:MyCanvas.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Draw the pie chart Arc2D.Float arc = new Arc2D.Float(Arc2D.PIE); arc.setFrame(140, 200, 67, 46);//from w ww. j a v a2s.c o m arc.setAngleStart(45); arc.setAngleExtent(270); g2.setColor(Color.gray); g2.draw(arc); g2.setColor(Color.red); g2.fill(arc); g2.setColor(Color.black); g2.drawString("Arc2D.PIE", 140, 190); }
From source file:CompoundBorderLineLineBorder.java
public CompoundBorderLineLineBorder() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JLabel label;//from ww w . j ava 2s . c o m label = new JLabel("Compound - red inside green lines"); label.setBorder(BorderFactory.createCompoundBorder(new LineBorder(Color.green), new LineBorder(Color.red))); panel.add(label); getContentPane().add(panel); pack(); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AttributedString astr = new AttributedString("aString"); astr.addAttribute(TextAttribute.FONT, new Font("", 1, 30), 1, 2); astr.addAttribute(TextAttribute.BACKGROUND, Color.red, 2, 3); TextLayout tl = new TextLayout(astr.getIterator(), g2d.getFontRenderContext()); tl.draw(g2d, 10, 20);/*www . j av a 2s . co m*/ }
From source file:Main.java
public Main() { setLayout(new FlowLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); table = new Hashtable<Integer, Color>(); table.put(1, Color.RED); table.put(2, Color.BLUE);/* www . j ava 2 s.c o m*/ table.put(3, Color.GREEN); table.put(4, Color.GRAY); c = new JComboBox<String>(); c.addItem("Item 1"); c.addItem("Item 2"); c.addItem("Item 3"); c.addItem("Item 4"); c.addItem("Item 5"); c.addItem("Item 6"); c.addItem("Item 7"); c.addItem("Item 8"); c.setRenderer(new MyListCellRenderer(table)); add(c); setSize(400, 400); setVisible(true); }
From source file:ColorBlocks.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension d = getSize();//ww w. jav a2 s. c o m g2.translate(d.width / 2, d.height / 2); Color[] colors = { Color.white, Color.lightGray, Color.gray, Color.darkGray, Color.black, Color.red, Color.pink, Color.orange, Color.yellow, Color.green, Color.magenta, Color.cyan, Color.blue }; float size = 25; float x = -size * colors.length / 2; float y = -size * 3 / 2; // Show all the predefined colors. for (int i = 0; i < colors.length; i++) { Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size); g2.setPaint(colors[i]); g2.fill(r); } //a linear gradient. y += size; Color c1 = Color.yellow; Color c2 = Color.blue; for (int i = 0; i < colors.length; i++) { float ratio = (float) i / (float) colors.length; int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio)); int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio)); int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio)); Color c = new Color(red, green, blue); Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size); g2.setPaint(c); g2.fill(r); } // Show an alpha gradient. y += size; c1 = Color.red; for (int i = 0; i < colors.length; i++) { int alpha = (int) (255 * (float) i / (float) colors.length); Color c = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), alpha); Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size); g2.setPaint(c); g2.fill(r); } // Draw a frame around the whole thing. y -= size * 2; Rectangle2D frame = new Rectangle2D.Float(x, y, size * colors.length, size * 3); g2.setPaint(Color.black); g2.draw(frame); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f); BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); gbi.setPaint(Color.red); gbi.fillRect(0, 0, 40, 40);// w w w . j a va 2 s.c om gbi.setComposite(ac); gbi.setPaint(Color.green); gbi.fillRect(5, 5, 40, 40); g2d.drawImage(buffImg, 20, 20, null); }
From source file:ColoredToolTipExample.java
public ColoredToolTipExample() { super("Colored ToolTip Example"); UIManager.put("ToolTip.foreground", new ColorUIResource(Color.red)); UIManager.put("ToolTip.background", new ColorUIResource(Color.yellow)); JButton button = new JButton("Hello, world"); button.setToolTipText("Red / Yellow"); getContentPane().add(button);//from www. ja va 2 s . co m }
From source file:CompositingDST.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST, 0.5f); BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); gbi.setPaint(Color.red); gbi.fillRect(0, 0, 40, 40);// w w w .j ava2 s. c o m gbi.setComposite(ac); gbi.setPaint(Color.green); gbi.fillRect(5, 5, 40, 40); g2d.drawImage(buffImg, 20, 20, null); }
From source file:CheckBoxIcon.java
public void paintIcon(Component component, Graphics g, int x, int y) { AbstractButton abstractButton = (AbstractButton) component; ButtonModel buttonModel = abstractButton.getModel(); Color color = buttonModel.isSelected() ? Color.BLUE : Color.RED; g.setColor(color);//w w w . ja va2 s.c om g.drawRect(1, 1, 20, 20); }