📄 imagepreviewpane.java
字号:
/*
* 11/14/2003
*
* ImagePreviewPane.java - An accessory for JFileChoosers that displays a
* preview of image (gif or jpg) files.
* Copyright (C) 2003 Robert Futrell
* email@address.com
* www.website.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.fife.ui;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Image;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
/**
* An accessory panel for <code>javax.swing.JFileChooser</code>s that are used
* for picking image files (<code>gif</code> or <code>jpg</code>). The panel
* displays a "preview" of the currently selected image.
*
* @author Robert Futrell
* @version 1.0
*/
public class ImagePreviewPane extends JComponent
implements PropertyChangeListener {
/**
*
*/
private static final long serialVersionUID = 1480475325221563180L;
private JLabel imageLabel;
/*****************************************************************************/
/**
* Creates a new <code>ImagePreviewPane</code>.
*/
public ImagePreviewPane() {
setLayout(new GridLayout(1,1));
setBorder(BorderFactory.createTitledBorder("Preview"));
imageLabel = new JLabel();
imageLabel.setPreferredSize(new Dimension(120,120));
add(imageLabel);
}
/*****************************************************************************/
/**
* Listens for when the user selects a new file in the parent
* <code>javax.swing.JFileChooser</code>.
*/
public void propertyChange(PropertyChangeEvent e) {
if (e.getPropertyName().equals(JFileChooser.
SELECTED_FILE_CHANGED_PROPERTY)) {
File file = (File)e.getNewValue();
if (file!=null) {
Image image = new ImageIcon(file.getAbsolutePath()).
getImage().getScaledInstance(120,120,
Image.SCALE_DEFAULT);
imageLabel.setIcon(new ImageIcon(image));
repaint();
}
}
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -