Results 1 to 2 of 2
  1. #1
    masa is offline Member
    Join Date
    Nov 2008
    Posts
    21
    Rep Power
    0

    Default how to set image to a jpanel

    i have a swing application where i have to load an image and do some annotations on it. the application contains two toolbars. one toolbar contains buttons such as loading an image,zoom in,zoom out etc. other toolbar contains buttons such as drawing circles,rectangles on the image. so what i did is i have added these two toolbars to two separate panels and added it to frame. first frame as horizontal panel and added to the north of frame and second toolbar as vertical panel added to the west. now i declared the remaining part of the frame as third panel where the actual image is seen and can be modified. my problem is if the image is small it is showing the image in the center and if the image is big it is added with the scrollbar which i provided. i want to change the size of this panel whenever i add an image to this panel either a big image or a small. i mean i want to assign the size of the image to the size of the panel. hope you understand my problem...........i cannot load the code as it is huge one.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,415
    Rep Power
    20

    Default

    On loading an image, setPreferredSize of the panel to be same as the size of the image and pack() the frame.

    db

Similar Threads

  1. Replies: 14
    Last Post: 04-10-2009, 08:46 AM
  2. Canvas Image popups another image (SWT)
    By SpaceY in forum New To Java
    Replies: 2
    Last Post: 11-11-2008, 01:25 PM
  3. Replies: 5
    Last Post: 11-02-2008, 06:41 AM
  4. drawing an image to an offscreen image
    By hunterbdb in forum Java 2D
    Replies: 9
    Last Post: 10-30-2008, 06:17 PM
  5. Replies: 0
    Last Post: 01-08-2008, 05:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •