2 Replies Latest reply: May 28, 2010 8:11 AM by 800414 RSS

    Graphics Cut text inside a shape

      hello all ,
      using Graphics i want to paint an oval
      and cut a text in the middle of it
      how can i achieve that ?

      Edited by: shay_te on 12:06 28/05/2010
        • 1. Re: Graphics Cut text inside a shape
          ok i soled it
          import java.awt.Color;
          import java.awt.Component;
          import java.awt.Font;
          import java.awt.Graphics;
          import java.awt.Graphics2D;
          import java.awt.Image;
          import java.awt.RenderingHints;
          import java.awt.image.BufferedImage;
          import java.awt.image.FilteredImageSource;
          import java.awt.image.ImageFilter;
          import java.awt.image.RGBImageFilter;
          public class IconInformation implements SizableIcon {
            private int m_size = 20;
            public int getIconHeight(){
              return m_size;
            public int getIconWidth(){
              return m_size;
            public void paintIcon(Component c, Graphics g, int x, int y){
              BufferedImage src = new BufferedImage(m_size, m_size, BufferedImage.TYPE_INT_BGR);
              Graphics2D g2 = (Graphics2D)src.getGraphics();
              Object hintOriginal = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
              g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
              g2.fillOval(0, 0, m_size, m_size);
              g2.setFont(new Font("arial" ,Font.BOLD ,m_size));
              g2.drawString("i", (m_size/2), (m_size/2) + 5);
              g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hintOriginal);
              ImageFilter colorfilter = new BlueFilter();
              Image img = c.createImage(new FilteredImageSource(src.getSource(), colorfilter));
              g.drawImage(img, x, y, m_size,m_size, c);
            public void setSize(int size){
              m_size = size;
            class BlueFilter extends RGBImageFilter {
              public int filterRGB(int x, int y, int rgb){
                Color color = new Color(rgb);
                if (color.equals(Color.BLUE)){ // If the pixel is white, it is transparent
                  return 0;
                return rgb;
          Edited by: shay_te on 13:11 28/05/2010
          • 2. Re: Graphics Cut text inside a shape
            i answered it my self ,
            details in post