Java 使用Icon

本文详细介绍了在Java中如何使用Icon进行图形界面增强,包括加载图标资源、设置图标到组件以及自定义图标的方法,帮助开发者提升GUI应用的用户体验。
摘要由CSDN通过智能技术生成




package com.han;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;

/**
 * If the graphic files are loaded from an initial thread, there may be a delay
 * before the GUI appears. If the graphic files are loaded from the event
 * dispatch thread, the GUI may be temporarily unresponsive. So we use
 * SwingWorker as a background processing for the loading of image files.
 * <p>
 * This application needs the customization of the image files' informations in
 * the private inner class "LoadImages".
 * 
 * @author HAN
 * @version 1.0
 * @see IconDemoAPP2 version 2.0
 */
@SuppressWarnings("serial")
public class IconDemoAPP extends JPanel {
	private static JFrame frame;
	private JLabel photoLabel;
	private JToolBar toolBar;
	private int displayZone = 400;

	/**
	 * The constructor serves as the content pane construction.
	 */
	IconDemoAPP() {
		// JPanel uses FlowLayout by default. We set it to BorderLayout for
		// use of tool bar. This JPanel will be used as content pane.
		setLayout(new BorderLayout());

		// Creat
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值