Skip to main content

JRendererLabel

1 reply [Last post]
Spinnifex
Offline
Joined: 2011-03-29
Points: 0

Hi,

My question is about the JRendererLabel.

At the JavaDoc I read the following :
"A JLabel optimized for usage in renderers and with a minimal background painter support."

I thought this is the perfect component for my trees/tables etc.
But a week ago I wonder why my tree table is so slow...
I checked the performance with the VisualVM-Tool. This pointed me to
the paint-Method of JRendererLabel.
After replacing the JRendererLabel with JXLabel I got a much better performance for
my tree table ( JXTreeTable ).

My TreeCellRenderer looks like this :

public class FileSystemTTableTreeRenderer extends JRendererLabel implements
        TreeCellRenderer {
 
   // ...  

    @Override
    public Component getTreeCellRendererComponent( JTree tree, Object value,
                                                   boolean selected,
                                                   boolean expanded,
                                                   boolean leaf, int row,
                                                   boolean hasFocus ) {
        // Valid node
        if ( value != null ) {

           
            setText( /**...*/ );
            setIcon( /**...*/ );
        }
        else {
            setText( "Error" );
            setIcon( null );
        }

        return this;
    }
}

So my question is where should I use JRendererLabel and where not?

Some performance tests later showed me, that the best way to paint my cells
was do inherit from JComponent and draw a custom BufferedImage at it's paintComponent-Method.
( The tree table should paint a large file system , so more then 10000 rows are not uncommon )
Regards,

Spinni

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

That's not the SwingX way of handling it. Do NOT subclass JRendererLabel. Use the StringValue, IconValue interfaces to configure the contents. These are passed in the DefaultXXXRenderer classes.

Karl