Finally got it to work
Code:import java.awt.Frame; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.JDialog; import javax.swing.SwingUtilities; import javax.swing.Timer; public class JDialogNotification extends JDialog { private static final long serialVersionUID = 9077763988467568226L; private static int getTrayheight() { return (Toolkit.getDefaultToolkit().getScreenSize().height - GraphicsEnvironment .getLocalGraphicsEnvironment().getMaximumWindowBounds().height); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JDialogNotification dialog = new JDialogNotification( new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } public JDialogNotification(Frame owner, boolean modal) { super(owner, modal); initComponents(); setWindowLocation(); } // Dialog motion private void dialogMotion(final JDialog mainDialog, final int x, final int y) { AbstractAction abAction = new AbstractAction() { private static final long serialVersionUID = -1005676924292901160L; public void actionPerformed(ActionEvent evnt) { mainDialog.setLocation(x, y); } }; Timer motionTimer = new Timer(300, abAction); motionTimer.setRepeats(false); motionTimer.start(); } private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); javax.swing.GroupLayout layout = new javax.swing.GroupLayout( getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 138, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 112, Short.MAX_VALUE)); pack(); } // Set the main window display location public void setWindowLocation() { try { int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; int frameHeight = this.getHeight(); int frameWidth = this.getWidth(); int _xValue = screenWidth - frameWidth; int _yValue = screenHeight - getTrayheight(); int _yEnd = screenHeight - frameHeight - getTrayheight(); // this.setLocation((screenWidth - frameWidth), (screenHeight - // frameHeight - getTrayheight() - WINDOW_SPACE)); this.setLocation(_xValue, _yValue); while (_yValue > _yEnd) { dialogMotion(this, _xValue, _yValue); _yValue -= 1; } Thread.sleep(1000); SwingUtilities.invokeLater(new Runnable() { public void run() { try { Thread.sleep(1500); System.exit(0); } catch (InterruptedException e) { e.printStackTrace(); } } }); } catch (InterruptedException ex) { Logger.getLogger(JDialogNotification.class.getName()).log( Level.SEVERE, null, ex); } } }





Reply With Quote