My problem is that I do not get the message in my taskbar using a displayMessage
I have the following code:
private JFrame parent;
private PopupMenu popup = new PopupMenu();
private final Image image = new ImageIcon(getClass().getResource("Notificacion.png")).getImage();
private final TrayIcon trayIcon = new TrayIcon(image, "Notificacion.png", popup);
//para el Timer
private Timer timer;
///////////////////////////
SystemTray systemTray;
Class constructor
public Notificacion(JFrame frame) {
this.parent = frame;
instanciarTray();
segundoPlano();
}
The methods instantiateTray () and secondPlan ()
private void instanciarTray() {
trayIcon.setImageAutoSize(true);
systemTray = SystemTray.getSystemTray();
}
private void segundoPlano() {
try {
if (SystemTray.isSupported()) {
systemTray.add(trayIcon);
parent.setVisible(false);
//Se inicia una tarea cuando se minimiza
if (timer != null) {
timer.cancel();
}
timer = new Timer();
timer.schedule(new miTimerTask(), 2000, 5000);//Se ejecuta cada 5 segundos
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR);
}
}
I have a method called MessageTrayIcon which I use to call it from my class miTimerTask which runs every X seconds but it does not work, I do not get the notification message .
public void MensajeTrayIcon(String texto, MessageType tipo) {
trayIcon.displayMessage("Advertencia.", texto, tipo);
}
Class miTimerTask
public class miTimerTask extends TimerTask{
Controlador controlador = new Controlador();
Notificacion notificacion = new Notificacion();
@Override
public void run() {
buscarAchivosExtenciones();
}
public void buscarAchivosExtenciones(){
controlador.buscarArchivosPndUnicos(new File("D:\Gerardo\Sustemas\Java\Netbans\Alerta\Alerta\src\CarpetaDirectorio\Nueva carpeta"));
notificacion.MensajeTrayIcon("Haciendo algo: ", MessageType.INFO);
}
}
If I call my message method within secondPlan I get the message in the notifications bar but only once, I need it to leave every time the system performs an action, that's why I call it in my class miTimerTask but the call does not work, I'm not doing it wrong. Thanks again.