简体   繁体   English

如何在jgrapht或jgraphx中更改所选连接的颜色?

[英]How to change color of selected connection in jgrapht or jgraphx?

I'm visualizing a graph in a java swing application using jgrapht/jgraphx. 我正在使用jgrapht / jgraphx在Java swing应用程序中可视化图形。

By default the connections (the arrows that point from one node to an other) between 2 nodes are rendered in light blue. 默认情况下,两个节点之间的连接(从一个节点指向另一个节点的箭头)显示为浅蓝色。 When I select a connection by clicking on it, the color changes from light blue to green. 当我通过单击选择连接时,颜色从浅蓝色变为绿色。

How can I change this color? 如何更改此颜色? I didn't find a way to do this so far. 到目前为止,我还没有找到一种方法。 I'm using jgrapht 0.9.1, jgraphx 2.0.0.1, jgraph 5.13.0.0. 我正在使用jgrapht 0.9.1,jgraphx 2.0.0.1,jgraph 5.13.0.0。

(EDIT: tested this for JgraphX 3.4.1.3) (编辑:针对JgraphX 3.4.1.3对此进行了测试)

This selection color is defined in mxSwingConstants.java . 此选择颜色在mxSwingConstants.java定义。

It can be overwritten by: 可以通过以下方式覆盖它:

     mxSwingConstants.EDGE_SELECTION_COLOR = new Color(255,0,0,255);

But this is not so pretty I would say, and you cannot set it differently for different edges like this. 但这不是我想说的那么漂亮,并且您不能像这样针对不同的边缘进行不同的设置。 Probably you can change it after some event. 可能您可以在某些事件后更改它。

A pretty solution would be if one could add it to an edge style... 一个不错的解决方案是,如果可以将其添加到边缘样式中...

这是正确的方法(我认为)

    mxCellTracker trackColor = new mxCellTracker(myGraphComponent, Color.CYAN);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM