made statusbar clickable

This commit is contained in:
2022-01-30 10:29:14 +01:00
parent 7f9797bcaa
commit 7573753263
3 changed files with 26 additions and 1 deletions

View File

@@ -1,5 +1,11 @@
package de.srsoftware.belegscanner.gui;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
@@ -8,6 +14,8 @@ import javax.swing.border.EmptyBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.srsoftware.belegscanner.Application;
/**
* Simple status barwith updateable text.
* This class may be extended to show more status information.
@@ -25,8 +33,24 @@ public class StatusBar extends JPanel {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(path = new JLabel("Kein Pfad gewält."));
path.setBorder(new EmptyBorder(5,5,5,5));
path.setToolTipText(Application.t("Click here to open directory"));
path.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
openDir();
}
});
}
protected void openDir() {
try {
File dir = new File(path.getText());
if (dir.exists()) Desktop.getDesktop().open(dir);
} catch (IOException e) {
e.printStackTrace();
}
}
public StatusBar setPath(String path) {
LOG.debug("setPath({})",path);
this.path.setText(path);