scala.swing: Trying to scale images to window size, but size returns 0 -
it should go without saying, i'm new swing.
i'm trying make simple little thing display 2 images side side, large window allow.
in theory happening is:
we imageicon, in case 001.jpg.
we figure out ratio of width/height of imageicon.
we turn imageicon image.
we turn image new correctly sized image.
we turn image image icon.
this breaks down because way i've found window size size, keeps returning 0s.
this code have right now:
class ui extends mainframe { title = "matt's window header" preferredsize = new dimension(1920, 1080) var imageicon = new imageicon("001.jpg") val imgratio = imageicon.geticonwidth.todouble / imageicon.geticonheight.todouble println(size) pack() println(imgratio) val image = imageicon.getimage() val newimg = image.getscaledinstance(size.width, (size.width * imgratio.toint), java.awt.image.scale_smooth) imageicon = new imageicon(newimg) contents = new label { icon = imageicon } } as aside, great if give me info how load different image, instead of 001.jpg.
sizeis not determined @ point accessing it. however, preferredsizeis. if add println(preferredsize) dimensions set.
Comments
Post a Comment