对于任何仍在摸不着头脑的人,这里有两个简单的类可以更改未选取的顶点/边缘标签颜色。
public class MyDefaultVertexLaberRenderer extends DefaultVertexLabelRenderer
{
protected Color unpickedVertexLabelColor = Color.BLACK;
public MyDefaultVertexLaberRenderer(Color unpickedVertexLabelColor, Color pickedVertexLabelColor)
{
super(pickedVertexLabelColor);
this.unpickedVertexLabelColor = unpickedVertexLabelColor;
}
public <V> Component getVertexLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, V vertex)
{
super.setForeground(unpickedVertexLabelColor);
if (isSelected) setForeground(pickedVertexLabelColor);
super.setBackground(vv.getBackground());
if (font != null)
{
setFont(font);
}
else
{
setFont(vv.getFont());
}
setIcon(null);
setBorder(noFocusBorder);
setValue(value);
return this;
}
}
public class MyDefaultEdgeLaberRenderer extends DefaultEdgeLabelRenderer
{
protected Color unpickedEdgeLabelColor = Color.BLACK;
public MyDefaultEdgeLaberRenderer(Color unpickedEdgeLabelColor, Color pickedEdgeLabelColor)
{
super(pickedEdgeLabelColor);
this.unpickedEdgeLabelColor = unpickedEdgeLabelColor;
}
public <E> Component getEdgeLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, E edge)
{
super.setForeground(unpickedEdgeLabelColor);
if (isSelected) setForeground(pickedEdgeLabelColor);
super.setBackground(vv.getBackground());
if (font != null)
{
setFont(font);
}
else
{
setFont(vv.getFont());
}
setIcon(null);
setBorder(noFocusBorder);
setValue(value);
return this;
}
}