JThreadKit Home

JTKLabel Demo - Instructions

Overview

The class JTKLabel is a great tool for building thread-safe gui's. JTKLabel is a JThreadKit Swing component that adds some great additional features to a JLabel. The feature highlighted in the demo is the ability to safely set the label text (from a helper Thread) without the need to create a Runnable Object and call SwingUtilities.invokeLater(). You simply create a JTKLabel Object by passing a JLabel to the constructor:

JTKLabel label = new JTKLabel(new JLabel("Start"));

Now any Thread can call the setTextSafely() method to update the label text. Note: JTKLabel is not a subclass of Component. To add the wrapped JLabel to a Container, simply do the following:

container.add(label.getLabel());

Running the Demo

Once the demo appears, click the "Start" button. The label text will now start changing approximately every second. You can stop and restart the demo if you wish, or simply close the window to end it.