Fala aí pessoal, boa noite, tudo bem? Estou mexendo em uma notificação aqui e me surgiu a dúvida de como fazer a notificação “subir” a altura, no GIF vocês vão ver,
O objeto é criado (e eu fiz uma gambiarrazinha), se existir ele cria com um position +120, por enquanto funciona legal, mas eu tenho ctz absoluta que não é o jeito correto. Visualmente está assim:
pra chamar o JDialog:
private int i = 20;
private boolean click = false;
private void callNotification() {
if (!click) {
i += 20; //se for a primeira notificacao, position 20
new NotificationSucesso(this, false, i).setVisible(true);
click = true;
} else {
i += 120; //senao for a primeira +120
new NotificationSucesso(this, false, i).setVisible(true);
}
}
Deixei tudo no construtor pra facilitar aqui:
public NotificationSucesso(java.awt.Frame parent, boolean modal, int position) {
super(parent, modal);
initComponents();
new RoundFrame().corner(this, 450, 100, 10, 10); //metodo insignificante agora
new TocarSom().tocarSomNotificacao(); //metodo insignificante agora
//Faz ficar no canto superior direito
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();
int x = (int) rect.getMaxX() - getWidth() - 20;
//seta o position
setLocation(x, position);
//fecha depois de 5 segundos
new Thread() {
@Override
public void run() {
try {
Thread.sleep(5000);
dispose();
} catch (Exception e) {
}
}
}.start();
}
Se alguém puder ajudar, agradeço!!
Ficou meio confuso a dúvida:
Eu queria saber qual é o jeito correto de fazer isso E (não tão importante assim) fazer a notificação subir quando outra “sumir”