resize image


hello there,

I get my image into a Jframe from the database which workes fine.but now my problem is the images are of different sizes.how can i adjust the JFrame according the image.

public static void main(String[]args)
      {
            Frame frame = new DBImage();            
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Dimension scrnsize = toolkit.getScreenSize();
            //frame.setSize( (int) scrnsize.getWidth(),(int)scrnsize.getHeight());
            frame.setSize(700,100);
            frame.show();
      }

cheers
zolf
zolfAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
(and you can get rid of any manual sizing)
0
 
CEHJCommented:
Change

frame.show();

to

frame.pack();
0
 
girionisCommented:
Try

Dimension size = frame.getSize();
int width = size.width;
int height = size.height;
frame.setSize(new Dimension(width, height));
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
girionisConnect With a Mentor Commented:
> int width = size.width;
> int height = size.height;

should be getWidth() and getHeight()
0
 
girionisCommented:
> frame.setSize(new Dimension(width, height));

and this should be different, set to the frame you want, otherwise you will resize the same frame :) Didn'ty wake up completely yet :)
0
 
CEHJCommented:
SOrry! My first answer has a silly error. Of course i meant

 Change

frame.setSize(......................................);

to

frame.pack();
0
 
CEHJCommented:
:-)
0
All Courses

From novice to tech pro — start learning today.