forked from fanruan/finekit
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.3 KiB
84 lines
2.3 KiB
package com.fanruan.api.design.ui.component; |
|
|
|
import javax.swing.event.MouseInputAdapter; |
|
import java.awt.*; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
import java.awt.event.MouseEvent; |
|
|
|
/** |
|
* @author richie |
|
* @version 10.0 |
|
* Created by richie on 2019-08-28 |
|
* 可以点击的标签(带超链接效果) |
|
*/ |
|
public class UIActionLabel extends UILabel { |
|
|
|
private ActionListener actionListener; |
|
|
|
public UIActionLabel(String text) { |
|
super(text); |
|
|
|
this.setForeground(Color.blue); |
|
this.addMouseListener(mouseInputAdapter); |
|
this.addMouseMotionListener(mouseInputAdapter); |
|
} |
|
|
|
public void addActionListener(ActionListener actionListener) { |
|
this.actionListener = actionListener; |
|
} |
|
|
|
public void paintComponent(Graphics _gfx) { |
|
super.paintComponent(_gfx); |
|
|
|
_gfx.setColor(Color.blue); |
|
_gfx.drawLine(0, this.getHeight() - 1, this.getWidth(), this.getHeight() - 1); |
|
} |
|
|
|
private MouseInputAdapter mouseInputAdapter = new MouseInputAdapter() { |
|
public void mouseClicked(MouseEvent e) { |
|
} |
|
|
|
public void mousePressed(MouseEvent e) { |
|
} |
|
|
|
public void mouseReleased(MouseEvent evt) { |
|
Object source = evt.getSource(); |
|
|
|
if (source instanceof UILabel) { |
|
//Action. |
|
if (actionListener != null) { |
|
ActionEvent actionEvent = new ActionEvent(source, 99, ""); |
|
actionListener.actionPerformed(actionEvent); |
|
} |
|
} |
|
} |
|
|
|
public void mouseEntered(MouseEvent evt) { |
|
Object source = evt.getSource(); |
|
|
|
if (source instanceof UILabel) { |
|
((UILabel) source).setCursor(new Cursor(Cursor.HAND_CURSOR)); |
|
} |
|
} |
|
|
|
public void mouseExited(MouseEvent evt) { |
|
Object source = evt.getSource(); |
|
|
|
if (source instanceof UILabel) { |
|
((UILabel) source).setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
|
} |
|
} |
|
|
|
public void mouseDragged(MouseEvent e) { |
|
} |
|
|
|
public void mouseMoved(MouseEvent evt) { |
|
Object source = evt.getSource(); |
|
|
|
if (source instanceof UILabel) { |
|
((UILabel) source).setCursor(new Cursor(Cursor.HAND_CURSOR)); |
|
} |
|
} |
|
}; |
|
}
|
|
|