我创建了一个属性编辑器:
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
重绘?
谢谢