Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing - user alerts

Tags:

java

swing

I am trying to build a user alert mechanism by bringing up the window to the front and then flashing the icon on the screen for the user. I have two questions with regards to this approach:

  1. How can you find the current window you are at in Java and then de-minimize it and bring to front?
  2. Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?

Thanks a lot for any replies.

like image 722
Bober02 Avatar asked Aug 14 '12 08:08

Bober02


Video Answer


1 Answers

How can you find the current window you are at in Java and then de-minimize it and bring to front

Window[] allWindows = Window.getWindows(); 
  • returns arrays of all Top-Level Containers from current JVM e.g. J/Frame, J/Dialog(JOptionPane), J/Window,

  • you can to test for (example) if (allWindows[i] instanceof JFrame) {

  • then WindowState returned WindowEvent

by bringing up the window to the front and then flashing the icon on the screen for the user

use undecodated JDialog (works toFront, toBack) with

  • create only once time

  • setDefaultCloseOperations(HIDE_ON_CLOSE)

  • use Swing Timer for hide JDialog

Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?

  • have look at Java Translucent Window, put there Icon to the JLabel (or to the JButton)

use Swing Timer for flashing by hiding Icon or swithing bewtween two or more Icons (three or four is good)

like image 99
mKorbel Avatar answered Sep 27 '22 21:09

mKorbel