I'm trying to display text on GlassPane in front of image which I read in. There is no problem with image which does display but my text doesn't appear. What is wrong????
import java.io.File;
import java.io.IOException;
import java.awt.*;
import java.awt.image.RenderedImage;
import javax.swing.*;
import javax.media.jai.widget.ScrollingImagePanel;
import javax.media.jai.NullOpImage;
import javax.media.jai.OpImage;
import com.sun.media.jai.codec.SeekableStream;
import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.ImageCodec;
public class FlashText extends JFrame
{
public void runFlashText() throws IOException
{
JFrame viewImg = new JFrame();
Dimension dim = new Dimension(676, 900);
viewImg.setSize(dim);
viewImg.setTitle("Multi page TIFF Reader");
File file = new File("colour_img.tif");
SeekableStream s = new FileSeekableStream(file);
TIFFDecodeParam param = null;
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
System.out.println("Number of images in this TIFF: " +
dec.getNumPages());
// Which of the multiple images in the TIFF file do we want to load
// 0 refers to the first, 1 to the second and so on.
int imageToLoad = 0;
RenderedImage op =
new NullOpImage(dec.decodeAsRenderedImage(imageToLoad),
null,
OpImage.OP_IO_BOUND,
null);
ScrollingImagePanel myImg = new ScrollingImagePanel(op, 706, 910);
viewImg.add(myImg);
MyGlassPane myGlassPane = new MyGlassPane();
myGlassPane.setVisible(true);
viewImg.setGlassPane(myGlassPane);
viewImg.setVisible(true);
}
public class MyGlassPane extends JComponent
{
protected void painComponent(Graphics g)
{
g.setFont(new Font("Serif", Font.BOLD, 50 ));
String str = "MY TEXT";
g.drawString(str, 200, 200);
}
}
public static void main(String[] args) throws IOException
{
FlashText flashText = new FlashText();
flashText.runFlashText();
}
}