![](/img/trans.png)
[英]How to add a mouse listener to a JTree so that I can change the cursor (to a hand cursor) when hovering over a node?
[英]Prefuse. When hovering over a node, how can I change the connected edges' visualization?
當鼠標懸停在上面時,我使用這個典型的代碼段(來自預示例)來更改節點之一的顏色:
ColorAction nFill = new ColorAction(NODES, VisualItem.FILLCOLOR);
nFill.setDefaultColor(ColorLib.gray(255));
nFill.add("_hover", ColorLib.gray(200));
我也想將此節點的出入邊緣的顏色設置為不同的顏色,最好將ins的顏色設置為與outs的顏色不同,但是我找不到合適的謂詞。
我正在使用有向圖,以防萬一。
有沒有一種方法可以遍歷謂詞API中當前節點/邊的子級/父級? 您對我的實際問題有解決方案嗎?
我找到了一種無需謂詞的方法,但是通過創建自己的ColorAction子類:
class ConnectedEdgeColorAction extends ColorAction {
final int outgoing = ColorLib.rgb(255, 100, 100);
final int incoming = ColorLib.rgb(100, 255, 100);
final int none = ColorLib.gray(100);
public ConnectedEdgeColorAction(String group, String field) {
super(group, field);
}
@Override
public int getColor(VisualItem item) {
if (item instanceof EdgeItem) {
if (((EdgeItem) item).getSourceItem().isHover()) {
return outgoing;
} else if (((EdgeItem) item).getTargetItem().isHover()) {
return incoming;
}
}
return none;
}
}
然后,將其用作邊緣的主要顏色操作:
ColorAction nEdges = new ConnectedEdgeColorAction(EDGES, VisualItem.STROKECOLOR);
我不知道這是否是“首選”方式,但對我來說效果很好。
另一個解決方案可以遵循
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.