JLabel 不像按钮,要添加鼠标事件的话 用鼠标事件监听: JLabel jl = new JLabel(); jl.addMouseListener(new MouseListener(){ public void mouseClicked(MouseEvent e) { // 处理鼠标点击 } public void mouseEntered(MouseEve
JLabel jl = new JLabel();
jl.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {
// 处理鼠标点击
}
public void mouseEntered(MouseEvent e) {
// 处理鼠标移入
}
public void mouseExited(MouseEvent e) {
// 处理鼠标离开
}
public void mousePressed(MouseEvent e) {
// 处理鼠标按下
}
public void mouseReleased(MouseEvent e) {
// 处理鼠标释放
}
});JLabel label1 = new JLabel("默认保存路径:");
label1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fileChooser.showOpenDialog(fileChooser);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String filePath = fileChooser.getSelectedFile()
.getAbsolutePath();//这个就是你选择的文件夹的路径
System.out.println("filePath = " + filePath);
tfSavePath.setText(filePath);
//TODO 日期:2020-12-04T17:17:39.372Z 目的: 设置默认保存路径
// ZhihuUtils.setPrivateInfo("defSavePath",filePath);
}
}
});