mxGraph 设置默认Edge样式

本文介绍如何在mxgraphSwing操作中修改默认样式,包括通过编辑mxStylesheet.java中的createDefaultEdgeStyle方法实现节点线的弯曲连接,以及如何调整Cell的基本样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在mxgraph Swing 操作中,单击某个cell连接其他cell的节点线是,默认样式是直线连接,没有节点弯曲的设置。可以修改mxgraph的jar包中的mxStylesheet.java 对应的createDefaultEdgeStyle方法,在其中添加:style.put("edgeStyle", mxEdgeStyle.ElbowConnector); 即可。

	/**
	 * Creates and returns the default edge style.
	 * 
	 * @return Returns the default edge style.
	 */
	protected Map<String, Object> createDefaultEdgeStyle()
	{
		Map<String, Object> style = new Hashtable<String, Object>();
		style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR);
		style.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC);
		style.put(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
		style.put(mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
		style.put(mxConstants.STYLE_STROKECOLOR, "#6482B9");
		style.put(mxConstants.STYLE_FONTCOLOR, "#446299");
		style.put("edgeStyle", mxEdgeStyle.ElbowConnector);   //新添加的样式

		return style;
	}

这个文件里面也可以修改 Cell样式,方法是:

	/**
	 * Creates and returns the default vertex style.
	 * 
	 * @return Returns the default vertex style.
	 */
	protected Map<String, Object> createDefaultVertexStyle()
	{
		Map<String, Object> style = new Hashtable<String, Object>();

		style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
		style.put(mxConstants.STYLE_PERIMETER, mxPerimeter.RectanglePerimeter);
		style.put(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
		style.put(mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
		style.put(mxConstants.STYLE_FILLCOLOR, "#C3D9FF");
		style.put(mxConstants.STYLE_STROKECOLOR, "#6482B9");
		style.put(mxConstants.STYLE_FONTCOLOR, "#774400");

		return style;
	}

===================华丽丽的分割线==================

2014-04-20

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mixiao25184

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值