All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.tornado.databinding.model.PropertyListCellRenderer Maven / Gradle / Ivy

Go to download

Swing Data Binding is a powerful, fast, light and simple data binding framework for Java.

The newest version!
package no.tornado.databinding.model;

import no.tornado.databinding.Binding;

import javax.swing.*;
import java.awt.*;

public class PropertyListCellRenderer extends DefaultListCellRenderer {
    private String propertyExpression;

    public PropertyListCellRenderer(String propertyExpression) {
        this.propertyExpression = propertyExpression;
    }

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        return super.getListCellRendererComponent(list, value == null ? null : getPropertyValue(value), index, isSelected, cellHasFocus);
    }

    private Object getPropertyValue(Object value) {
        try {
            return Binding.propertyUtils.getNestedProperty(value, propertyExpression);
        } catch (Exception e) {
            e.printStackTrace();
            return "Failed to get " + propertyExpression;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy