How to add images icon in the title bar of JFrame?

家住魔仙堡 提交于 2019-12-11 11:28:50

问题


I need to add image in JFrame title bar, can anybody tell me the way to do this?


回答1:


You could use Window#setImageIcons(List<Image>) which allows you to supply a series of different sized, which allows the underlying platform to choose a icon that is best suited to the platform and look and feel...

List<Image> images = new ArrayList<Image>(4);
images.add(ImageIO.read(getClass().getResource("/icons/icon16x16.png"));
images.add(ImageIO.read(getClass().getResource("/icons/icon24x24.png"));
images.add(ImageIO.read(getClass().getResource("/icons/icon32x32.png"));
images.add(ImageIO.read(getClass().getResource("/icons/icon48x48.png"));

frame.setImageIcons(images);



回答2:


use frame.setIconImage(Image image) see http://docs.oracle.com/javase/6/docs/api/javax/swing/JFrame.html for details. Use BufferedImage to represent your image.



来源:https://stackoverflow.com/questions/13817565/how-to-add-images-icon-in-the-title-bar-of-jframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!