以下代码可以实现缩放:
ResourceMap resourceMap = getResourceMap();
ImageIcon imageIcon = resourceMap.getImageIcon("jLabel1.icon");
Image image = imageIcon.getImage();
Image smallImage = image.getScaledInstance(jLabel.getWeight(), jLabel.getHeight(),Image.SCALE_FAST);
ImageIcon smallIcon = new ImageIcon(smallImage);
jLabel1.setIcon(smallIcon);但是问题是,代码应该放在什么位置,放在initComponents之后的话,getWeight,getHeight函数的返回值都是0.造成错误,其他的像“Post-creation code”之类的地方也试过了,不行,请问应该放在哪里?
ResourceMap resourceMap = getResourceMap();
ImageIcon imageIcon = resourceMap.getImageIcon("jLabel1.icon");
Image image = imageIcon.getImage();
Image smallImage = image.getScaledInstance(jLabel.getWeight(), jLabel.getHeight(),Image.SCALE_FAST);
ImageIcon smallIcon = new ImageIcon(smallImage);
jLabel1.setIcon(smallIcon);但是问题是,代码应该放在什么位置,放在initComponents之后的话,getWeight,getHeight函数的返回值都是0.造成错误,其他的像“Post-creation code”之类的地方也试过了,不行,请问应该放在哪里?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货