Thursday October 11, 2007
PropertyEditorSupport.paintValue
I've been trying to see how much can be done with the PropertyEditorSupport.paintValue, partly because the development team we met in Budapest want to display an image in a properties sheet. It doesn't seem to be possible, the drawImage doesn't seem to work, from what I can tell. However, some other humble effects are possible, such as rectangles with rounded corners:
@Override
public void paintValue(java.awt.Graphics g, java.awt.Rectangle box) {
Rectangle r = g.getClipBounds();
g.drawRoundRect(1, 1, 270, 16, 10, 10);
g.drawString(getAsText(), box.x + 5, box.y + 15);
}
Assuming isPaintable is true, the above results in:
And a bit more can be done, like this:
@Override
public void paintValue(java.awt.Graphics g, java.awt.Rectangle box) {
Rectangle r = g.getClipBounds();
g.setColor(Color.yellow);
g.fillRoundRect(1, 1, 270, 16, 10, 10);
g.drawRoundRect(1, 1, 270, 16, 10, 10);
g.setColor(Color.blue);
g.drawString(getAsText(), box.x + 5, box.y + 15);
}
And that results in:

But it would be cool if at least a 16x16 icon could be shown. Ideally, the cell space would be extendable so that larger pictures could be shown. But, I'm sure that that isn't possible at all and a custom editor would need to be created, though that wouldn't display pictures within the cell itself.
Update: If you follow the discussion in the comments to this blog entry, you will end up with an icon in the property sheet, as shown here:
![]()
Oct 11 2007, 01:20:28 AM PDT Permalink


