• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to make Icon flash?

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a frame that has a panel to show messages. If frame is minimized, how to make the icon flash when new message arrives??
Thank you.
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I too had the same problem when i was developing a chat application. As far as i know, u can never make the frame blink. What u can do is make the frame popup and toFront when a message arrives at it. If u can make the frame blink, please let me know how u do it
..thanks
..saj
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's how to make the icon on the frame flash...

You have to have a clear image to use for the 'no icon' though... mine is called 'NoCursor.gif'...

Run the code a couple of times to see what it is doing... it's using AWT, but if you need to do this in Swing the same general idea applies...

 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Nathan,
"Truely Awesome"!!
Manjunath
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, Nathan Pruett
This is cool, but does not work on Solaris.
I need it to flash when I min frame on Solaris.
Do you know how to make it work on Sun box?
Thank you, Yarik.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For some reason getIconImage() returns null on the Solaris platform... I guess that there isn't a "generic" Java icon provided with the Solaris version of the JDK... The easiest way to get around this is to make a gif image to serve as the normal icon for your program and load it in the first index of the array in the same way you load the blank icon in the second index( "NoCursor.gif" in the above example. ). I tried this out on my Ultra 10 at work with Java 1.3 installed on it, and it worked fine.

Also, it doesn't just have to be an opaque icon and a clear icon... you can have a blinking light( one image of light out, and one of light on ), or frames for an animated image( increase the size of the image array and have one image for each frame of the animation ).

Hope this helps,
-Nate
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Nathan
This is what I did:
I created a class IndicatorPanel it flashes a message on a panel and flashes an Icon.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.siac.secmon.ExceptionHandler;
public class IndicatorPanel extends JPanel {
JLabel lbError = new JLabel();
String noError = new String(" ");
String Error = new String("!!! NEW MESSAGE ARRIVED !!!");
Thread flash = new Flash();
JFrame frame = null;
Image[] icons = null;
private boolean shouldFlash = false;
public IndicatorPanel(JFrame frame) {
BoxLayout lytErrorPanel = new BoxLayout(this,BoxLayout.X_AXIS);
this.setLayout(lytErrorPanel);
this.frame = frame;
lbError.setText(noError);
this.add(Box.createHorizontalGlue());
this.add(lbError);
this.add(Box.createHorizontalGlue());
if(frame != null){
icons = new Image[3];
icons[0]=Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("SmileyAngry.jpg"));
icons[1]=Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("SmileyAngry1.jpg"));
icons[2]=Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("Smiley2.jpg")); }
}
public void startFlashing(){
if (! shouldFlash){
shouldFlash = true;
new Flash().start();
}
}
public void stopFlashing(){
shouldFlash = false;
}
private class Flash extends Thread{
public void run(){
while(shouldFlash){
lbError.setText(Error);
lbError.setForeground(Color.red);
lbError.updateUI();
if(frame != null){
frame.setIconImage(icons[0]);
}
try{
Thread.currentThread().sleep(200);
}catch(InterruptedException ie){
} // end try
lbError.setForeground(Color.black);
lbError.updateUI();
if(frame != null){
frame.setIconImage(icons[1]);
}
try{
Thread.currentThread().sleep(200);
}catch(InterruptedException ie){
} // end try
}// end while
lbError.setText(noError);
lbError.updateUI();
if(frame != null){
frame.setIconImage(icons[2]);
}
}
}
}// END :~

I add the panel to a frame and pass the frame as an arg.
It works fine on WIN but once I put it on Solaris 2.6 the Icon does not get loaded at all. I can see some pic after minimizing the frame, it even changes color the way it suppose to, but teh image is very unclear. It is like watching TV with very bad reception.
Do you know why?
Thank you, Yarik.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The bad image quality could have several reasons...

  • You're using a jpeg... the amount of compression of the JPEG may look fine at whatever resolution your windows machine is, but look extra crappy on whatever resolution your solaris machine uses... this also impacts several of the other reasons I'm going to list... The only way to fix this is to go back in whatever program you used to make the graphics and save them as GIFs instead of JPEGs.
  • Icons can only be a fixed size, so your images are scaled... this impacts JPEGs moreso than GIFs, but can make your images look messed up in any case... try to make your images small enough so they don't have to be scaled. ( Sometimes impossible, but if you can do it it helps... )
  • Solaris and Windows graphics contexts are different in some strange way... just look at a graphically intensive web page on a Windows machine and then look at the same one on a Solaris machine... sometimes the images look brighter/darker, more/less grainy on different machines... The only way to work around this is pretty extreme... you could test different icons on different platforms to see which looked best and then set the icon of the frame based on what sort of machine was running your class ( by using System.getProperty( "os.name" ); )
 
reply
    Bookmark Topic Watch Topic
  • New Topic