简体   繁体   English

Java PropertyEditor-如何强制属性编辑器重新绘制(paintValue)

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

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. PropertyEditor似乎没有“重新绘制”或“无效”方法,因此我想知道如何使它重新绘制。

I have tried to invalidate/call repaint on the JLabel used to create the graphics, but it does not call paintValue() 我试图使用于创建图形的JLabel无效/调用重绘,但是它不调用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.... 我也尝试过直接调用该方法,但是我不知道从哪里获取GraphicsRectangle作为参数。

Anyone has an idea on how to force the PropertyEditor to repaint? 任何人都有关于如何强制PropertyEditor重新绘制的想法?

Thanks 谢谢

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() . 在后一种情况下,请尝试editor.getCustomEditor().repaint()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM