📄 jmimage.java
字号:
package jm.framework.gui.module;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import jm.util.JMCheck;
public class JMImage extends JLabel {
private static final long serialVersionUID = 2584166834338380201L;
Border defaultBorder = BorderFactory.createEtchedBorder();
JMIcon icon = null;
public JMImage(String filename) {
icon = new JMIcon(filename);
setDefault();
setBorder(defaultBorder);
}
public JMImage(URL location) {
icon = new JMIcon(location);
setDefault();
setBorder(defaultBorder);
}
public JMImage(Image image) {
icon = new JMIcon(image);
setDefault();
setBorder(defaultBorder);
}
public JMImage(byte[] imageData) {
icon = new JMIcon(imageData);
setDefault();
setBorder(defaultBorder);
}
/**
* Sets the border of this component. The <code>Border</code> object is
* responsible for defining the insets for the component (overriding any
* insets set directly on the component) and for optionally rendering any
* border decorations within the bounds of those insets. Borders should be
* used (rather than insets) for creating both decorative and non-decorative
* (such as margins and padding) regions for a swing component. Compound
* borders can be used to nest multiple borders within a single component.
* <p>
* Although technically you can set the border on any object that inherits
* from <code>JComponent</ocde>, the look and
* feel implementation of many standard Swing components
* doesn't work well with user-set borders. In general,
* when you want to set a border on a standard Swing
* component other than <code>JPanel</code> or <code>JLabel</code>,
* we recommend that you put the component in a <code>JPanel</code>
* and set the border on the <code>JPanel</code>.
* <p>
* This is a bound property.
*
* @param border the border to be rendered for this component
* @see Border
* @see CompoundBorder
* @beaninfo
* bound: true
* preferred: true
* attribute: visualUpdate true
* description: The component's border.
*/
public void setBorder(Border border) {
this.defaultBorder = border;
super.setBorder(defaultBorder);
}
private void setDefault() {
setIcon(icon);
setHorizontalAlignment(SwingConstants.CENTER);
setHorizontalTextPosition(SwingConstants.CENTER);
addMouseListener(new MouseAdapter() {
/**
* Invoked when the mouse has been clicked on a component.
*/
public void mouseClicked(MouseEvent e) {
}
/**
* Invoked when a mouse button has been pressed on a component.
*/
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
setBorder(BorderFactory.createLoweredBevelBorder());
}
}
/**
* Invoked when a mouse button has been released on a component.
*/
public void mouseReleased(MouseEvent e) {
setBorder(BorderFactory.createRaisedBevelBorder());
}
/**
* Invoked when the mouse enters a component.
*/
public void mouseEntered(MouseEvent e) {
setBorder(BorderFactory.createRaisedBevelBorder());
}
/**
* Invoked when the mouse exits a component.
*/
public void mouseExited(MouseEvent e) {
setBorder(defaultBorder);
}
});
}
public synchronized void addMouseListener(MouseListener l) {
super.addMouseListener(l);
}
public void setHelp(String iHelp) {
if (!JMCheck.isNull(iHelp)) {
setToolTipText(iHelp);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -