Java PropertyEditor - How to force a repaint (paintValue) of the property editor

305 views Asked by At

I have created a property editor :

import ca.cmhc.ifm.portal.dataservice.dataobjects.location.Region;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.beans.PropertyEditorSupport;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import org.openide.explorer.propertysheet.ExPropertyEditor;
import org.openide.explorer.propertysheet.PropertyEnv;

/**
 *
 * @author lbard
 */
public class MessagePropertyEditor extends PropertyEditorSupport implements ExPropertyEditor {

    private String localValue = "";
    private PropertyEnv env;
    private ArrayList<Region> regions;
    private String messageText = "";
    private JLabel renderer;

    public MessagePropertyEditor(String messageText) {
        super();
        this.messageText = messageText;
        renderer = new JLabel(this.messageText);
    }

    @Override
    public String getAsText() {
        return "";
    }


    @Override
    public boolean isPaintable() {
        return true;
    }

    @Override
    public void paintValue(final Graphics g, final Rectangle r)
    {
        renderer.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
        renderer.setForeground(Color.blue);
        //renderer.setText("<html><i>" + this.messageText.replace("\n", " ") + "</i>");
        renderer.setText(this.messageText.replace("\n", " "));
        renderer.setBounds(r);
        renderer.paint(g);
    }

    @Override
    public Component getCustomEditor() {
        MessageCustomEditor panel = new MessageCustomEditor(messageText);
        return panel;
    }

    @Override
    public boolean supportsCustomEditor() {
        return true;
    }

    public void attachEnv(PropertyEnv env) {
        this.env = env;
    }
}

I am trying to find a way to force a repaint of this component. The objective in the end is to have a timer change the background color at specific intervals, making the background flash. The PropertyEditor does not seem to have a "repaint" or a "invalidate" method, so I was wondering how to get it to repaint.

I have tried to invalidate/call repaint on the JLabel used to create the graphics, but it does not call paintValue()

I have also tried to call the method directly, but I do not know where to get Graphics and the Rectangle needed as parameters....

Anyone has an idea on how to force the PropertyEditor to repaint?

Thanks

1

There are 1 answers

1
Mad Physicist On

Do you want to repaint the property editor, or the component that represents it on the screen? In the latter case, try editor.getCustomEditor().repaint().