的重繪(paintValue):的Java屬性編輯器 - 如何強制我創建了一個屬性編輯器屬性編輯器
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
重繪?
謝謝
我會想象它是通過PropertyChangeListener對組件[PropertyEditorSupport]的支持(http://docs.oracle.com/javase/7/docs/api/java/beans/PropertyEditorSupport.html) – MadProgrammer
我不'不明白嗎?我將如何使用PropertyChangeListener重新繪製PropertyEditor? – JFTxJ
我不是100%確定!但考慮到它是唯一可用的聽衆!觸發PropertyChangeEvent可能會觸發已註冊的偵聽器更新其視圖... – MadProgrammer