List of usage examples for java.awt Graphics setColor
public abstract void setColor(Color c);
From source file:MyCanvas.java
public void paint(Graphics g) { int i = 10;/* w w w. ja va 2s . c o m*/ for (Color c : colors) { g.setColor(c); i += 10; g.drawLine(i, 10, 200, 200); } }
From source file:Main.java
public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(color); g.fillRect(x, y, w, H); }
From source file:ComplexCellRenderer.java
public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(Color.RED); g.drawRect(0, 0, 25, 25);//from w ww . ja v a 2 s . co m }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(underlineColor == null ? getForeground() : underlineColor); Insets insets = getInsets();// w w w . j a v a 2 s.c o m int left = insets.left; if (getIcon() != null) left += getIcon().getIconWidth() + getIconTextGap(); g.drawLine(left, getHeight() - 1 - insets.bottom, (int) getPreferredSize().getWidth() - insets.right, getHeight() - 1 - insets.bottom); }
From source file:OvalPanel.java
License:asdf
public void paintComponent(Graphics g) { int width = getWidth(); int height = getHeight(); g.setColor(color); g.drawOval(0, 0, width, height);/*w w w. jav a 2s . co m*/ }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.lightGray); int w = getWidth() / TILE + 1; int h = getHeight() / TILE + 1; for (int row = 0; row < h; row++) { for (int col = 0; col < w; col++) { if ((row + col) % 2 == 0) { g.fillRect(col * TILE, row * TILE, TILE, TILE); }// w w w .j a v a2 s .co m } } }
From source file:Main.java
public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(color); Polygon p = new Polygon(); if (state == State.NORMAL) { p.addPoint(x + (getIconWidth() / 2), y); p.addPoint(x, y + getIconHeight() - 1); p.addPoint(x + getIconWidth() - 1, y + getIconHeight() - 1); } else if (state == State.PRESSED) { p.addPoint(x, y);/*www. java2 s.com*/ p.addPoint(x + getIconWidth() - 1, y); p.addPoint(x + (getIconWidth() / 2), y + getIconHeight() - 1); } else { p.addPoint(x, y); p.addPoint(x, y + getIconHeight() - 1); p.addPoint(x + getIconWidth() - 1, y + (getIconHeight() / 2)); } g.fillPolygon(p); }
From source file:Main.java
public Main() { this.setLayout(new FlowLayout()); this.add(new JButton("test")); this.add(new JCheckBox("test")); this.add(new JRadioButton("test")); this.add(new JProgressBar(0, 100)); JPanel panel = new JPanel() { @Override//from w w w.j a va 2 s . co m public Dimension getPreferredSize() { return new Dimension(400, 300); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.red); g.fillRect(0, 0, getWidth(), getHeight()); } }; panel.add(new JLabel("Label")); add(panel); setSize(new Dimension(400, 300)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:MainClass.java
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.setColor(getWallColor()); // Paint a tall wall around the component for (int i = 0; i < sinkLevel; i++) { g.drawRoundRect(x + i, y + i, w - i - 1, h - i - 1, sinkLevel - i, sinkLevel); g.drawRoundRect(x + i, y + i, w - i - 1, h - i - 1, sinkLevel, sinkLevel - i); g.drawRoundRect(x + i, y, w - i - 1, h - 1, sinkLevel - i, sinkLevel); g.drawRoundRect(x, y + i, w - 1, h - i - 1, sinkLevel, sinkLevel - i); }/* ww w. j ava 2 s .c om*/ }
From source file:XORModePaintWithMouse.java
public void paint(Graphics g) { g.drawLine(0, 0, 100, 100);/*from ww w .ja va2 s.co m*/ g.drawLine(0, 100, 100, 0); g.setColor(Color.blue); g.drawLine(40, 25, 250, 180); g.drawLine(75, 90, 400, 400); g.setColor(Color.green); // xor cross hairs g.setXORMode(Color.black); g.drawLine(chsX - 10, chsY, chsX + 10, chsY); g.drawLine(chsX, chsY - 10, chsX, chsY + 10); g.setPaintMode(); }