[英]jgraphx change vertex size
我绘制了一个简单的图形(使用Java swing接口)。
该图还可以,但是默认/自动顶点的尺寸很小。 如何设置顶点大小(矩形或椭圆形)?
我可以使用put()更改某些图形行为(例如put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE))
但不能put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE))
顶点的大小。
该图还可以,但是默认/自动顶点的尺寸很小。 如何设置顶点大小(矩形或椭圆形)?
我可能对jgraphx有误解吗?
该文档非常难以理解,非常晦涩(至少对我来说是这样),我是否可以提出一些书籍或链接的建议以更好地理解Java jgraphx。
更详细一点:该图不是逐个元素构建的,而是来自使用jGraphXAdapter使用jgraphT构建的图
JGraphXAdapter<Incrocio, Strada> graphAdapter = new JGraphXAdapter<Incrocio, Strada>(listenableGraph);
感谢安德鲁的耐心配合。 英语不是我的语言,有时候我甚至会以意大利语(我的母语)犯错。 补充一点,我是Java新手。 即使在该论坛中也是新手(相关规则,这可能不是我重放的合适位置)。 之前,我没有仔细阅读您的留言。
我把代码,部分解决方案,我希望它更清楚。
package it.rex.view;
public class StradarioViewBis2 extends JFrame {
private JPanel contentPane;
// listenableGraph is a complete graph done with JgraphT
public StradarioViewBis2(ListenableGraph<Incrocio, Strada> listenableGraph) {
JGraphXAdapter<Incrocio, Strada> graphAdapter =
new JGraphXAdapter<Incrocio, Strada>(listenableGraph);
//graphAdapter.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1"); //remove label from edge
graphAdapter.getModel().beginUpdate();
try {
graphAdapter.clearSelection();
graphAdapter.selectAll();
Object[] cells = graphAdapter.getSelectionCells(); //here you have all cells
// Iterate into graph to change cells
for (Object c : cells) {
mxCell cell = (mxCell) c; //cast
mxGeometry geometry = cell.getGeometry();
if (cell.isVertex()) { //isVertex
// Here I can change vertex dimensions
geometry.setWidth(40);
geometry.setHeight(40);
}else{ //is not a vertex, so u can get source and target
// cell.setStyle("orthogonalEdgeStyle");
// cell.getChildAt(x); //Returns the child at the specified index. (target)
}
}
}
finally
{
graphAdapter.getModel().endUpdate();
}
mxIGraphLayout layout = new mxCircleLayout(graphAdapter); // questo sistema le posizione degli elementi
layout.execute(graphAdapter.getDefaultParent());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 550, 450);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
mxGraphComponent graphComponent = new mxGraphComponent(graphAdapter); // is JScrollPane extension
graphComponent.setPageVisible(true);
graphComponent.setBounds(30, 30, 300, 300);
contentPane.add(graphComponent);
//graphComponent.setEnabled(false);
graphComponent.getViewport().setBackground(Color.white);
;
}
}
经过一些尝试,我发现,当我更改单元格的标签时,而不是将焦点从单元格移开时,顶点的大小恢复到初始尺寸。
我想我需要更改图形的默认行为,但是我还没有发现如何做。
这是在顶部顶点上编辑标签后的结果: 在此处输入图像描述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.