0

我创建了一个属性编辑器:

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;
    }
}

我试图找到一种方法来强制重绘这个组件。最终的目标是让计时器以特定的时间间隔改变背景颜色,使背景闪烁。PropertyEditor似乎没有“重绘”或“无效”方法,所以我想知道如何让它重绘。

我试图JLabel使用于创建图形的对象无效/调用重绘,但它没有调用paintValue()

我也尝试过直接调用该方法,但不知道从哪里获取Graphics以及Rectangle所需的参数......

任何人都知道如何强制PropertyEditor重绘?

谢谢

4

1 回答 1

0

你想重新绘制属性编辑器,还是在屏幕上代表它的组件?在后一种情况下,尝试editor.getCustomEditor().repaint().

于 2014-01-06T20:00:26.847 回答