This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

How to resize an image or iimage?

General questions regarding the development with JVx.

Re: How to resize an image or iimage?

Postby rzenz » Thu Oct 19, 2017 3:43 pm

The UIIcon does support to set the alignment to STRETCH which will fit the image to the bounds of the component. Additionally it supports to preserve the aspect ratio to make sure that the image is not distorted. If you want an UIIcon to be a certain size you can set the preferred size of the component:

Code: Select all
UIIcon icon = new UIIcon(image);
icon.setHorizontalAlignment(UIIcon.ALIGN_STRETCH);
icon.setVerticalAlignment(UIIcon.ALIGN_STRETCH);
icon.setPreserveAspectRatio(true);
icon.setPreferredSize(800, 600);


This will make the UIIcon component to display the image as big as it is (with correct aspect ratio) and also the component will have a size of 800x600. Obviously, whether the preferred size is actually honored or not is dependent on the layout that is used. The UIBorderLayout for example does only honor parts of the set preferred size, or none at all, neither does the UIGridLayout. The other layouts (UIFormLayout, UIFlowLayout) do honor the preferred size (if applicable).

If you actually want to resize an image, there is the ImageUtil which allows you to do that.
User avatar
rzenz
 
Posts: 36
Joined: Mon Dec 12, 2016 1:40 pm
Location: Vienna, Austria

Return to Development