List of usage examples for java.awt Graphics setColor
public abstract void setColor(Color c);
From source file:DialogSeparator.java
public void paint(Graphics g) { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); Dimension d = getSize();//from w w w.ja v a 2 s . c o m int y = (d.height - 3) / 2; g.setColor(Color.white); g.drawLine(1, y, d.width - 1, y); y++; g.drawLine(0, y, 1, y); g.setColor(Color.gray); g.drawLine(d.width - 1, y, d.width, y); y++; g.drawLine(1, y, d.width - 1, y); String text = getText(); if (text.length() == 0) return; g.setFont(getFont()); FontMetrics fm = g.getFontMetrics(); y = (d.height + fm.getAscent()) / 2; int fontWidth = fm.stringWidth(text); g.setColor(getBackground()); g.fillRect(OFFSET - 5, 0, OFFSET + fontWidth, d.height); g.setColor(getForeground()); g.drawString(text, OFFSET, y); }
From source file:QandE.StripeBorder.java
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g.setColor(Color.RED); g.fillRect(x, y, c.getWidth(), HEIGHT); }
From source file:MainClass.java
public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(myColor); g.drawRect(0, 0, 16, 16);//from www . jav a 2 s . c o m }
From source file:Main.java
@Override public void paintComponent(Graphics g) { int margin = 10; Dimension dim = getSize();//from w w w . ja v a2s.c o m super.paintComponent(g); g.setColor(Color.red); g.fillRect(margin, margin, dim.width - margin * 2, dim.height - margin * 2); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.WHITE); int size = myModel.arraySize; int barWidth = getWidth() / size; for (int i = 0; i < size; i++) { int value = myModel.myArray[i]; int x = i * barWidth; int y = getHeight() - value; g.fillRect(x + 1, y, barWidth - 2, value); }// w ww. ja v a2 s .co m }
From source file:Main.java
public void paint(Graphics g) { Dimension d = getSize();//from w ww .j a v a 2s .c om int h = d.height; int w = d.width; g.setColor(color); if (rectangular) { g.fillRect(0, 0, w - 1, h - 1); } else { g.fillOval(0, 0, w - 1, h - 1); } }
From source file:Main.java
public void paint(Graphics g) { m_fm = g.getFontMetrics();//from w w w.ja v a 2 s .c o m g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight()); g.setColor(getForeground()); g.setFont(getFont()); Insets insets = getInsets(); int x = insets.left; int y = insets.top + m_fm.getAscent(); StringTokenizer st = new StringTokenizer(getText(), "\t"); while (st.hasMoreTokens()) { String str = st.nextToken(); g.drawString(str, x, y); //insert distance for each tab x += m_fm.stringWidth(str) + 50; if (!st.hasMoreTokens()) break; } }
From source file:DoubleBufferWithBufferedImage.java
public void paint(Graphics g) { Graphics screengc = null;/*from w w w .j av a 2 s . c o m*/ screengc = g; g = buffer.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, w, h); g.setColor(Color.red); for (int i = 0; i < w; i += gap) g.drawLine(i, 0, w - i, h); for (int i = 0; i < h; i += gap) g.drawLine(0, i, w, h - i); screengc.drawImage(buffer, 0, 0, null); }
From source file:Main.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(color); switch (value) { case 1:/*from ww w . j a va 2 s . c om*/ g.fillRect(3 * SIDE, 3 * SIDE, SIDE, SIDE); break; case 2: g.fillRect(5 * SIDE, SIDE, SIDE, SIDE); g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE); break; case 3: g.fillRect(5 * SIDE, SIDE, SIDE, SIDE); g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE); g.fillRect(3 * SIDE, 3 * SIDE, SIDE, SIDE); break; case 4: g.fillRect(SIDE, SIDE, SIDE, SIDE); g.fillRect(5 * SIDE, 5 * SIDE, SIDE, SIDE); g.fillRect(5 * SIDE, SIDE, SIDE, SIDE); g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE); break; case 5: g.fillRect(SIDE, SIDE, SIDE, SIDE); g.fillRect(5 * SIDE, 5 * SIDE, SIDE, SIDE); g.fillRect(5 * SIDE, SIDE, SIDE, SIDE); g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE); g.fillRect(3 * SIDE, 3 * SIDE, SIDE, SIDE); break; case 6: g.fillRect(SIDE, SIDE, SIDE, SIDE); g.fillRect(5 * SIDE, 5 * SIDE, SIDE, SIDE); g.fillRect(5 * SIDE, SIDE, SIDE, SIDE); g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE); g.fillRect(SIDE, 3 * SIDE, SIDE, SIDE); g.fillRect(5 * SIDE, 3 * SIDE, SIDE, SIDE); break; } }
From source file:OvalBorder.java
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { width--;/*from w w w. j a v a 2s . c om*/ height--; g.setColor(lightColor); g.drawLine(x, y + height - ovalHeight, x, y + ovalHeight); g.drawArc(x, y, 2 * ovalWidth, 2 * ovalHeight, 180, -90); g.drawLine(x + ovalWidth, y, x + width - ovalWidth, y); g.drawArc(x + width - 2 * ovalWidth, y, 2 * ovalWidth, 2 * ovalHeight, 90, -90); g.setColor(darkColor); g.drawLine(x + width, y + ovalHeight, x + width, y + height - ovalHeight); g.drawArc(x + width - 2 * ovalWidth, y + height - 2 * ovalHeight, 2 * ovalWidth, 2 * ovalHeight, 0, -90); g.drawLine(x + ovalWidth, y + height, x + width - ovalWidth, y + height); g.drawArc(x, y + height - 2 * ovalHeight, 2 * ovalWidth, 2 * ovalHeight, -90, -90); }