jlabel

JList image - rendering images in JList cells

Here's another JList example, this time sharing some JList code I use to render images and text in JList cells.

Before going on, if you just want to display a set of images in a JList, all you have to do is create your images as an array Icons, and then add this array to your JList, and you're done. The JList is smart enough to render a Java Icon as an image, so in the most simple case, that's all you have to do.

However, in my case, because I want to render an image and text in each cell, I need to do a little more work. If you want to do something like this, read on.

A Java tooltip tutorial

Java Swing FAQ: How do I create a Java tooltip (also known as balloon or bubble help text)?

A JLabel tooltip example

Java JLabel FAQ: How do I set the help text (i.e., help text, balloon text, tooltip text) on a JLabel?

Just call the setToolTipText method on the JLabel. Here's a quick JLabel tooltip display example:

// create a label with tooltip help text
JLabel label = new JLabel("Username");
label.setToolTipText("Enter your username");

Java animated GIF example

Someone asked yesterday if you can use animated GIF images in Java applications using the JFC/Swing toolkit. That's something I hadn't tried with Java and Swing before, so I wrote a quick test program, and sure enough they work.

I just load an animated GIF as an ImageIcon, then put it on a JLabel and display it on a JFrame, and the animation starts right up. Note that I'm using a Java/JDK 1.4.x release.

Java image example - simple ImageIcon and JLabel technique

Here is some sample Java source code that shows a simple technique to display a GIF, JPG, or PNG image using a Java ImageIcon and JLabel.

Java hyperlink - a JLabel hyperlink example

This Java class still needs some work, but it's my first attempt at creating a Java Swing component that simulates a hyperlink. Basically, if you use this label (a JHyperlinkLabel to be precise) instead of a JLabel you should see hyperlink behavior on your Swing labels (JLabel).

Java hyperlinks and the HyperLinkListener class

Using hypertext and hyperlinks in Java Swing applications makes them look more like web applications, and that's often a very good thing. Here's a quick example of how to add a Java HyperlinkListener to a component in Java. In this case the component I'm going to use is a JEditorPane.

Syndicate content