Instead of "hoping" you know the size of the button, you should make use of the ComponentListener API to receive notifications of when the component is actually resized. I need to be able to resize the button and of course its icon, but when the button gets to small the icon disappears. And while you can provide all the sizing hints you might like, the layout manager is well within its rights to ignore one or more of these hints. You should also remember, that the size of a component is not determined until it is laid out. You can also click and drag to set the required image size. Click over the area where you want to place the image to add the image in its original size. In the Open dialog box, choose one or multiple image files. Sure, might be a nice idea, but given the amount of time and processing required to do it efficiently, I understand why they don't, so you need to do all the work. Image img icon.getImage () Now create a buffered image the same size as the image: BufferedImage bi new BufferedImage (img.getWidth (null), img.getHeight (null), BufferedImage.TYPEINTARGB) Then blit the icon image to the buffered image, and resize it as you do so: Graphics g bi. To add an image to your design: Press M or select the Image tool on the toolbar. To start with, all Swing components DON'T auto scale images.
0 Comments
Leave a Reply. |