public void paintComponentBackground(Object nativeGraphics,int x,int y,int width,int height,Style s){
  if (width <= 0 || height <= 0) {
    return;
  }
  Image bgImageOrig=s.getBgImage();
  if (bgImageOrig == null) {
    if (s.getBackgroundType() >= Style.BACKGROUND_GRADIENT_LINEAR_VERTICAL) {
      drawGradientBackground(s,nativeGraphics,x,y,width,height);
      return;
    }
    setColor(nativeGraphics,s.getBgColor());
    fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
  }
 else {
    int iW=bgImageOrig.getWidth();
    int iH=bgImageOrig.getHeight();
    Object bgImage=bgImageOrig.getImage();
switch (s.getBackgroundType()) {
case Style.BACKGROUND_NONE:
      if (s.getBgTransparency() != 0) {
        setColor(nativeGraphics,s.getBgColor());
        fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
      }
    return;
case Style.BACKGROUND_IMAGE_SCALED:
  if (isScaledImageDrawingSupported()) {
    drawImage(nativeGraphics,bgImage,x,y,width,height);
  }
 else {
    if (iW != width || iH != height) {
      bgImageOrig=bgImageOrig.scaled(width,height);
      s.setBgImage(bgImageOrig,true);
      bgImage=bgImageOrig.getImage();
    }
    drawImage(nativeGraphics,bgImage,x,y);
  }
return;
case Style.BACKGROUND_IMAGE_SCALED_FILL:
float r=Math.max(((float)width) / ((float)iW),((float)height) / ((float)iH));
int bwidth=(int)(((float)iW) * r);
int bheight=(int)(((float)iH) * r);
if (isScaledImageDrawingSupported()) {
drawImage(nativeGraphics,bgImage,x + (width - bwidth) / 2,y + (height - bheight) / 2,bwidth,bheight);
}
 else {
if (iW != bwidth || iH != bheight) {
bgImageOrig=bgImageOrig.scaled(bwidth,bheight);
s.setBgImage(bgImageOrig,true);
bgImage=bgImageOrig.getImage();
}
drawImage(nativeGraphics,bgImage,x + (width - bwidth) / 2,y + (height - bheight) / 2);
}
return;
case Style.BACKGROUND_IMAGE_SCALED_FIT:
if (s.getBgTransparency() != 0) {
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
}
float r2=Math.min(((float)width) / ((float)iW),((float)height) / ((float)iH));
int awidth=(int)(((float)iW) * r2);
int aheight=(int)(((float)iH) * r2);
if (isScaledImageDrawingSupported()) {
drawImage(nativeGraphics,bgImage,x + (width - awidth) / 2,y + (height - aheight) / 2,awidth,aheight);
}
 else {
if (iW != awidth || iH != aheight) {
bgImageOrig=bgImageOrig.scaled(awidth,aheight);
s.setBgImage(bgImageOrig,true);
bgImage=bgImageOrig.getImage();
}
drawImage(nativeGraphics,bgImage,x + (width - awidth) / 2,y + (height - aheight) / 2,awidth,aheight);
}
return;
case Style.BACKGROUND_IMAGE_TILE_BOTH:
tileImage(nativeGraphics,bgImage,x,y,width,height);
return;
case Style.BACKGROUND_IMAGE_TILE_HORIZONTAL_ALIGN_TOP:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
tileImage(nativeGraphics,bgImage,x,y,width,iH);
return;
case Style.BACKGROUND_IMAGE_TILE_HORIZONTAL_ALIGN_CENTER:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
tileImage(nativeGraphics,bgImage,x,y + (height / 2 - iH / 2),width,iH);
return;
case Style.BACKGROUND_IMAGE_TILE_HORIZONTAL_ALIGN_BOTTOM:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
tileImage(nativeGraphics,bgImage,x,y + (height - iH),width,iH);
return;
case Style.BACKGROUND_IMAGE_TILE_VERTICAL_ALIGN_LEFT:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
for (int yPos=0; yPos <= height; yPos+=iH) {
drawImage(nativeGraphics,bgImage,x,y + yPos);
}
return;
case Style.BACKGROUND_IMAGE_TILE_VERTICAL_ALIGN_CENTER:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
for (int yPos=0; yPos <= height; yPos+=iH) {
drawImage(nativeGraphics,bgImage,x + (width / 2 - iW / 2),y + yPos);
}
return;
case Style.BACKGROUND_IMAGE_TILE_VERTICAL_ALIGN_RIGHT:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
for (int yPos=0; yPos <= height; yPos+=iH) {
drawImage(nativeGraphics,bgImage,x + width - iW,y + yPos);
}
return;
case Style.BACKGROUND_IMAGE_ALIGNED_TOP:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
drawImage(nativeGraphics,bgImage,x + (width / 2 - iW / 2),y);
return;
case Style.BACKGROUND_IMAGE_ALIGNED_BOTTOM:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
drawImage(nativeGraphics,bgImage,x + (width / 2 - iW / 2),y + (height - iH));
return;
case Style.BACKGROUND_IMAGE_ALIGNED_LEFT:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
drawImage(nativeGraphics,bgImage,x,y + (height / 2 - iH / 2));
return;
case Style.BACKGROUND_IMAGE_ALIGNED_RIGHT:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
drawImage(nativeGraphics,bgImage,x + width - iW,y + (height / 2 - iH / 2));
return;
case Style.BACKGROUND_IMAGE_ALIGNED_CENTER:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
drawImage(nativeGraphics,bgImage,x + (width / 2 - iW / 2),y + (height / 2 - iH / 2));
return;
case Style.BACKGROUND_IMAGE_ALIGNED_TOP_LEFT:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
drawImage(nativeGraphics,bgImage,x,y);
return;
case Style.BACKGROUND_IMAGE_ALIGNED_TOP_RIGHT:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
drawImage(nativeGraphics,bgImage,x + width - iW,y);
return;
case Style.BACKGROUND_IMAGE_ALIGNED_BOTTOM_LEFT:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
drawImage(nativeGraphics,bgImage,x,y + (height - iH));
return;
case Style.BACKGROUND_IMAGE_ALIGNED_BOTTOM_RIGHT:
setColor(nativeGraphics,s.getBgColor());
fillRect(nativeGraphics,x,y,width,height,s.getBgTransparency());
drawImage(nativeGraphics,bgImage,x + width - iW,y + (height - iH));
return;
case Style.BACKGROUND_GRADIENT_LINEAR_HORIZONTAL:
case Style.BACKGROUND_GRADIENT_LINEAR_VERTICAL:
case Style.BACKGROUND_GRADIENT_RADIAL:
drawGradientBackground(s,nativeGraphics,x,y,width,height);
return;
}
}
}

public void paintComponentBackground ( Object nativeGraphics , int x , int y , int width , int height , Style s ) { if ( width <= 0 || height <= 0 ) { return ; } Image bgImageOrig = s . getBgImage ( ) ; if ( bgImageOrig == null ) { if ( s . getBackgroundType ( ) >= Style . BACKGROUND_GRADIENT_LINEAR_VERTICAL ) { drawGradientBackground ( s , nativeGraphics , x , y , width , height ) ; return ; } setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; } else { int iW = bgImageOrig . getWidth ( ) ; int iH = bgImageOrig . getHeight ( ) ; Object bgImage = bgImageOrig . getImage ( ) ; switch ( s . getBackgroundType ( ) ) { case Style . BACKGROUND_NONE : if ( s . getBgTransparency ( ) != 0 ) { setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; } return ; case Style . BACKGROUND_IMAGE_SCALED : if ( isScaledImageDrawingSupported ( ) ) { drawImage ( nativeGraphics , bgImage , x , y , width , height ) ; } else { if ( iW != width || iH != height ) { bgImageOrig = bgImageOrig . scaled ( width , height ) ; s . setBgImage ( bgImageOrig , true ) ; bgImage = bgImageOrig . getImage ( ) ; } drawImage ( nativeGraphics , bgImage , x , y ) ; } return ; case Style . BACKGROUND_IMAGE_SCALED_FILL : float r = Math . max ( ( ( float ) width ) / ( ( float ) iW ) , ( ( float ) height ) / ( ( float ) iH ) ) ; int bwidth = ( int ) ( ( ( float ) iW ) * r ) ; int bheight = ( int ) ( ( ( float ) iH ) * r ) ; if ( isScaledImageDrawingSupported ( ) ) { drawImage ( nativeGraphics , bgImage , x + ( width - bwidth ) / 2 , y + ( height - bheight ) / 2 , bwidth , bheight ) ; } else { if ( iW != bwidth || iH != bheight ) { bgImageOrig = bgImageOrig . scaled ( bwidth , bheight ) ; s . setBgImage ( bgImageOrig , true ) ; bgImage = bgImageOrig . getImage ( ) ; } drawImage ( nativeGraphics , bgImage , x + ( width - bwidth ) / 2 , y + ( height - bheight ) / 2 ) ; } return ; case Style . BACKGROUND_IMAGE_SCALED_FIT : if ( s . getBgTransparency ( ) != 0 ) { setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; } float r2 = Math . min ( ( ( float ) width ) / ( ( float ) iW ) , ( ( float ) height ) / ( ( float ) iH ) ) ; int awidth = ( int ) ( ( ( float ) iW ) * r2 ) ; int aheight = ( int ) ( ( ( float ) iH ) * r2 ) ; if ( isScaledImageDrawingSupported ( ) ) { drawImage ( nativeGraphics , bgImage , x + ( width - awidth ) / 2 , y + ( height - aheight ) / 2 , awidth , aheight ) ; } else { if ( iW != awidth || iH != aheight ) { bgImageOrig = bgImageOrig . scaled ( awidth , aheight ) ; s . setBgImage ( bgImageOrig , true ) ; bgImage = bgImageOrig . getImage ( ) ; } drawImage ( nativeGraphics , bgImage , x + ( width - awidth ) / 2 , y + ( height - aheight ) / 2 , awidth , aheight ) ; } return ; case Style . BACKGROUND_IMAGE_TILE_BOTH : tileImage ( nativeGraphics , bgImage , x , y , width , height ) ; return ; case Style . BACKGROUND_IMAGE_TILE_HORIZONTAL_ALIGN_TOP : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; tileImage ( nativeGraphics , bgImage , x , y , width , iH ) ; return ; case Style . BACKGROUND_IMAGE_TILE_HORIZONTAL_ALIGN_CENTER : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; tileImage ( nativeGraphics , bgImage , x , y + ( height / 2 - iH / 2 ) , width , iH ) ; return ; case Style . BACKGROUND_IMAGE_TILE_HORIZONTAL_ALIGN_BOTTOM : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; tileImage ( nativeGraphics , bgImage , x , y + ( height - iH ) , width , iH ) ; return ; case Style . BACKGROUND_IMAGE_TILE_VERTICAL_ALIGN_LEFT : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; for ( int yPos = 0 ; yPos <= height ; yPos += iH ) { drawImage ( nativeGraphics , bgImage , x , y + yPos ) ; } return ; case Style . BACKGROUND_IMAGE_TILE_VERTICAL_ALIGN_CENTER : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; for ( int yPos = 0 ; yPos <= height ; yPos += iH ) { drawImage ( nativeGraphics , bgImage , x + ( width / 2 - iW / 2 ) , y + yPos ) ; } return ; case Style . BACKGROUND_IMAGE_TILE_VERTICAL_ALIGN_RIGHT : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; for ( int yPos = 0 ; yPos <= height ; yPos += iH ) { drawImage ( nativeGraphics , bgImage , x + width - iW , y + yPos ) ; } return ; case Style . BACKGROUND_IMAGE_ALIGNED_TOP : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; drawImage ( nativeGraphics , bgImage , x + ( width / 2 - iW / 2 ) , y ) ; return ; case Style . BACKGROUND_IMAGE_ALIGNED_BOTTOM : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; drawImage ( nativeGraphics , bgImage , x + ( width / 2 - iW / 2 ) , y + ( height - iH ) ) ; return ; case Style . BACKGROUND_IMAGE_ALIGNED_LEFT : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; drawImage ( nativeGraphics , bgImage , x , y + ( height / 2 - iH / 2 ) ) ; return ; case Style . BACKGROUND_IMAGE_ALIGNED_RIGHT : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; drawImage ( nativeGraphics , bgImage , x + width - iW , y + ( height / 2 - iH / 2 ) ) ; return ; case Style . BACKGROUND_IMAGE_ALIGNED_CENTER : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; drawImage ( nativeGraphics , bgImage , x + ( width / 2 - iW / 2 ) , y + ( height / 2 - iH / 2 ) ) ; return ; case Style . BACKGROUND_IMAGE_ALIGNED_TOP_LEFT : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; drawImage ( nativeGraphics , bgImage , x , y ) ; return ; case Style . BACKGROUND_IMAGE_ALIGNED_TOP_RIGHT : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; drawImage ( nativeGraphics , bgImage , x + width - iW , y ) ; return ; case Style . BACKGROUND_IMAGE_ALIGNED_BOTTOM_LEFT : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; drawImage ( nativeGraphics , bgImage , x , y + ( height - iH ) ) ; return ; case Style . BACKGROUND_IMAGE_ALIGNED_BOTTOM_RIGHT : setColor ( nativeGraphics , s . getBgColor ( ) ) ; fillRect ( nativeGraphics , x , y , width , height , s . getBgTransparency ( ) ) ; drawImage ( nativeGraphics , bgImage , x + width - iW , y + ( height - iH ) ) ; return ; case Style . BACKGROUND_GRADIENT_LINEAR_HORIZONTAL : case Style . BACKGROUND_GRADIENT_LINEAR_VERTICAL : case Style . BACKGROUND_GRADIENT_RADIAL : drawGradientBackground ( s , nativeGraphics , x , y , width , height ) ; return ; } } }
paints the background of a component based on the style values on the given graphics context , the style could be accessed from the drawing thread in read only capacity to make the code slightly more efficient
