Re: panels size on gridlayout

Discussion in 'Java' started by VisionSet, Jul 10, 2003.

  1. VisionSet

    VisionSet Guest

    "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
    news:7j_Oa.669$...
    > I have a scrollpane with a panel inside of it which has gridlayout. This
    > panel gets added other panels. My purpose is to add one panel below the
    > other (by below I am a little further down on the screen). The panels get
    > added fine but they contain images, images which I hope will take up the
    > whole panel so that the images on the panels above and below will touch,

    but
    > instead the images dont take the whole panel and the images dont touch. I
    > have checked the VGap and HGap of the gridlayout and thats not the

    problem,
    > I have also colored the background of the most inner panels and they do
    > touch each other, its just the images that seem to be small than the panel
    > size.
    > I am using AWT in case it wasnt clear.
    >


    Rewrite a *tiny* version of it, to track down the problem, if it still does
    it, post it here.

    --
    Mike W
    VisionSet, Jul 10, 2003
    #1
    1. Advertising

  2. VisionSet

    VisionSet Guest

    "Ike" <> wrote in message
    news:dIcPa.39465$...
    > Are the image sizes, when displayed, full size? i.e. is it that you want
    > them to "stretch," to take up the panel? If so, I have some blitting

    classes
    > I wrote to take an Image and a JPanel. Please let me know here. -Ike


    They are full size, they won't resize by default in the same way the panel
    does.
    You will have to write code that gets the size of the panel on each window
    change and reproduces the image appropriately.

    --
    Mike W
    VisionSet, Jul 10, 2003
    #2
    1. Advertising

  3. VisionSet

    Ike Guest

    Maybe this might help....it lets you do a lot in the way of how you want it
    layed out on the panel, including alpha....hth, Ike
    /**
    * This version uses a default alpha blend of 0% of the previous image,
    100% of current image
    * @param g the Graphics2D context
    * @param blitmode 1=raw at its natural size in upper left of picture at
    UpperLeftX,UpperLeftY
    * 2=draw at its natural size in center(UpperLeftX,UpperLeftY not used
    in blitMode==2)
    * 3=draw at its natural size tiled throughout
    * 4=scale it all into the view window, aspect ratio be damned
    * 5=scale it all into view, but maintain aspect ratio
    * 6=like 4&5 but do not scale it, use actual size
    * Note - methods 4,5 and 6 tile based on where you are in the window,
    1,2 and 3 do not
    * @param img the image to blit
    *@param UpperLeftX the left corner to put the image in
    *@param UpperLeftY the upper corner to put the image in
    *@param targWidth the width of the image after blitting
    *@param targHeight the heigh of the image after blitting
    *@param observer the ImageObserver itself
    */
    final static public void blit(Graphics2D g,int blitMode,Image img,int
    UpperLeftX, int UpperLeftY,int targWidth,int targHeight, ImageObserver
    observer){
    blit(g,blitMode,img,UpperLeftX, UpperLeftY,targWidth,targHeight,
    1.0F,1.0F,observer);
    }
    /**
    *
    * @param g the Graphics2D context
    * @param blitmode 1=raw at its natural size in upper left of picture at
    UpperLeftX,UpperLeftY
    * 2=draw at its natural size in center(UpperLeftX,UpperLeftY not used
    in blitMode==2)
    * 3=draw at its natural size tiled throughout
    * 4=scale it all into the view window, aspect ratio be damned
    * 5=scale it all into view, but maintain aspect ratio
    * 6=like 4&5 but do not scale it, use actual size
    * Note - methods 4,5 and 6 tile based on where you are in the window,
    1,2 and 3 do not
    * @param img the image to blit
    *@param UpperLeftX the left corner to put the image in
    *@param UpperLeftY the upper corner to put the image in
    *@param targWidth the width of the image after blitting
    *@param targHeight the heigh of the image after blitting
    *@param alpha the percentage (0.0f - 1.0f, inclusive) of the current
    image (img) to use
    *@param observer the ImageObserver itself
    */
    final static public void blit(Graphics2D g,int blitMode,Image img,int
    UpperLeftX, int UpperLeftY,int targWidth,int targHeight, float alpha,
    ImageObserver observer){
    blit(g,blitMode,img,UpperLeftX, UpperLeftY,targWidth,targHeight,
    alpha,1.0F, observer);
    }
    /**
    *
    * @param g the Graphics2D context
    * @param blitmode 1=raw at its natural size in upper left of picture at
    UpperLeftX,UpperLeftY
    * 2=draw at its natural size in center(UpperLeftX,UpperLeftY not used
    in blitMode==2)
    * 3=draw at its natural size tiled throughout
    * 4=scale it all into the view window, aspect ratio be damned
    * 5=scale it all into view, but maintain aspect ratio
    * 6=like 4&5 but do not scale it, use actual size
    * Note - methods 4,5 and 6 tile based on where you are in the window,
    1,2 and 3 do not
    * @param img the image to blit
    *@param UpperLeftX the left corner to put the image in
    *@param UpperLeftY the upper corner to put the image in
    *@param targWidth the width of the image after blitting
    *@param targHeight the heigh of the image after blitting
    *@param alpha the percentage (0.0f - 1.0f, inclusive) of the current
    image (img) to use
    *@param alphaOver the percentage (0.0f - 1.0f, inclusive) of the images
    to be painted over this bitmap to use
    *@param observer the ImageObserver itself
    */
    final static public void blit(Graphics2D g,int blitMode,Image img,int
    UpperLeftX, int UpperLeftY,int targWidth,int targHeight, float alpha, float
    alphaOver, ImageObserver observer){

    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha));
    if (blitMode==1){
    //draw at its natural size in upper left of picture at
    UpperLeftX,UpperLeftY
    g.drawImage(img,UpperLeftX,UpperLeftY,observer);
    }else if (blitMode==2){
    //draw at its natural size in center
    //UpperLeftX,UpperLeftY not used in blitMode==2
    float x = (float)(img.getWidth(observer));
    float y = (float)(img.getHeight(observer));
    float tWidth=(float) targWidth;
    float tHeight=(float) targHeight;
    tWidth=tWidth/2-x/2;
    tHeight=tHeight/2-y/2;
    if(x>0.0 && y>0.0)

    g.drawImage(img,UpperLeftX+(int)tWidth,UpperLeftY+(int)tHeight,observer);
    }else if (blitMode==3){
    //draw at its natural size tiled throughout
    int x = img.getWidth(observer);
    int y = img.getHeight(observer);
    int xcount,ycount;
    xcount=ycount=1;
    if(x>0 && y>0){
    while (x*xcount<targWidth+x){
    while (y*ycount<targHeight+y){
    g.drawImage(img,x*(xcount-1),y*(ycount-1),observer);
    ycount++;
    }
    ycount=1;
    xcount++;
    }
    }
    }else if (blitMode==4){
    //scale it all into the view window, aspect ratio be damned

    g.drawImage(img,UpperLeftX,UpperLeftY,UpperLeftX+targWidth,UpperLeftY+targHe
    ight, observer);
    }else if(blitMode>4){
    //scale it all into the view - tries to get most of it in the
    view without changing the aspect ratio
    float xratio, yratio;
    float x = (float)(img.getWidth(observer));
    float y = (float)(img.getHeight(observer));
    float tWidth=(float) targWidth;
    float tHeight=(float) targHeight;

    if(x>0.0 && y >0.0){
    if(blitMode==5){
    xratio = x/tWidth;
    yratio = y/tHeight;
    }else{
    xratio=yratio=1.0f;
    }
    // x&y are width & height of picture file rect
    // tWidth & tHeight are width & height of target rect

    if(xratio <= yratio){
    g.drawImage(img,UpperLeftX,UpperLeftY,
    /*ulx+*/(int)(x/xratio),/* uly+*/(int)(y/xratio) , observer);
    }else{
    g.drawImage(img,UpperLeftX,UpperLeftY,
    /*ulx+*/(int)(x/yratio), /*uly+*/(int)(y/yratio), observer);
    }
    }else{

    g.drawImage(img,UpperLeftX,UpperLeftY,/*ulx+*/targWidth,/*uly+*/targHeight,
    observer);
    }
    }
    //set alpha back so controls can draw

    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alphaOver)
    );
    }
    Ike, Jul 10, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian
    Replies:
    0
    Views:
    359
    Christian
    Jul 21, 2003
  2. Kenneth

    Gridlayout problems

    Kenneth, Oct 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    356
    Cowboy \(Gregory A. Beamer\)
    Oct 15, 2003
  3. Stephen

    flowlayout vs. gridlayout

    Stephen, Dec 5, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    5,938
    mikeb
    Dec 5, 2003
  4. Ike
    Replies:
    2
    Views:
    373
  5. Jo

    Size of GridLayout

    Jo, Apr 10, 2004, in forum: Java
    Replies:
    2
    Views:
    1,290
    Jim Cobban
    Apr 10, 2004
Loading...

Share This Page