首页 > 代码库 > Java Swing 之查看图标信息
Java Swing 之查看图标信息
/** *查看图标的信息 *@author gao */ package com.gao; import java.awt.FlowLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; public class ImageInfoDemo extends JFrame{ public ImageInfoDemo (){ this.setTitle("查看图标信息"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setBounds(100, 100, 300, 150); JPanel contentPane=new JPanel(); contentPane.setBorder(new EmptyBorder(5,5,5,5)); this.setContentPane(contentPane); contentPane.setLayout(new FlowLayout(FlowLayout.CENTER,5,5)); JLabel label=new JLabel(""); ImageIcon icon=new ImageIcon("1.png"); label.setIcon(icon); StringBuilder sb=new StringBuilder(); sb.append("图标宽度:"+icon.getIconWidth()+","); sb.append("图标高度:"+icon.getIconHeight()); label.setText(sb.toString()); contentPane.add(label); this.setVisible(true); } public static void main(String []args){ ImageInfoDemo example=new ImageInfoDemo(); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。