开发者

Resizing JLabel smaller than its icon?

开发者 https://www.devze.com 2023-03-03 09:53 出处:网络
I\'m using a JPanel containing a JLabel with an icon. I\'m using a ComponentAdapter on the JLabel to request a correctly sized thumbnail from the controller (using MVC pattern) when the JLabel is resi

I'm using a JPanel containing a JLabel with an icon. I'm using a ComponentAdapter on the JLabel to request a correctly sized thumbnail from the controller (using MVC pattern) when the JLabel is resized. This works fine when the JLabel is resized to be bigger than before, so then it's filled with an ImageIcon the size of the JLabel. However, when resizing the window to be smaller, it simply doesn't resize the JLabel at all (because of the icon's size, I'm assuming).

Is there possibly some layout m开发者_运维百科anager or setting to make the JLabel disregard its content (the ImageIcon) and resize itself anyways? I mean, it can truncate text, so it ought to be able to just show part of the image when resized smaller.


Try experimenting with setPreferredSize() and setMinimumSize() to ensure the JLabel is allowing itself to shrink to the required size. You also need to double-check what kind of LayoutManager you are using and what constraints, if any, you use when adding your component to the panel. Try a different layout manager if you can. If none of that works, you will need to provide some example code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号