Reputation: 372
I'm using a JDialog to display notifications in bottom right corner of my application. I'm displaying up to 4 notifications and the most recent on is on top. Notifications are showing according to content from server, so there could be just 1 notification or 3, maximum 4. That causes resizing of JDialog and resizing causes to change location of JDialog in order to be always aligned in bottom right corner. Changing location on every new notification income causes flickering of JDialog.
Below is code which i call everytime when new notification come:
private void updateDialog()
{
Point p = frame.getLocationOnScreen();
p.x += frame.getWidth()-getWidth()-5;
p.y += frame.getHeight()-getHeight()-25;
setLocation(p);
pack();
repaint();
}
Did anybody have simliar problem? How did you solve it? Any other advice on what should i try to do?
Upvotes: 0
Views: 677
Reputation: 109823
contraproductive is code line with repaint(), remove that,
if isn't there another code lines inside void updateDialog(), then better would be, otherwise pack() should be wrapped into invokeLater();
code
private void updateDialog() {
setVisible(false);
Point p = frame.getLocationOnScreen();
p.x += frame.getWidth() - getWidth() - 5;
p.y += frame.getHeight() - getHeight() - 25;
setLocation(p);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
pack();
//repaint(); // useless remove this codeline
setVisible(true);
}
});
}
Upvotes: 3