本文介绍了JUNG:取消了顶点标签颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用像这样声明的vertexLabelRenderer使选择的顶点标签为红色:

I can make picked vertex labels red using vertexLabelRenderer declared like this:

DefaultVertexLabelRenderer vertexLabelRenderer=new DefaultVertexLabelRenderer(Color.RED);

如何更改取消顶部顶点标签的颜色。构造函数(见下文)仅允许定义未压缩顶点标签。方法setForeground()不会影响字体颜色。

How do I change color of unpicked vertex labels. Constructor (see below) only allows defining unpicked vertex labels. Also method setForeground() does not affect the font color.

这里是JUNG 2.0.1 API文档:

Here is the JUNG 2.0.1 API document:http://jung.sourceforge.net/site/apidocs/edu/uci/ics/jung/visualization/renderers/DefaultVertexLabelRenderer.html

推荐答案

对于任何人还在搔头这里有两个简单的类

For anyone still scratching their head here's two simple classes that can change an unpicked vertex/edge label color.

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;
    }
}

这篇关于JUNG:取消了顶点标签颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 03:30