微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

顶点中的文本未居中

如何解决顶点中的文本未居中

当创建一个带有文本值的顶点时,它会在中间上方放置几个像素。不同的字体大小处于不同的高度。文本也小于我输入的字体大小。如何让文本居中显示在单元格中?

这是我使用的样式表。

int TFontSize = 15;
mxStylesheet stylesheet = graph.getStylesheet();
Hashtable<String,Object> style = new Hashtable<String,Object>();
style.put(mxConstants.STYLE_SHAPE,mxConstants.SHAPE_ELLIPSE);
style.put(mxConstants.STYLE_FILLCOLOR,"white");
style.put(mxConstants.STYLE_strokeCOLOR,"black");
style.put(mxConstants.STYLE_FONTCOLOR,"black");
style.put(mxConstants.STYLE_FONTFAMILY,"Arial");
style.put(mxConstants.STYLE_FONTSIZE,TFontSize);

stylesheet.putCellStyle("teamS",style);

这是创建单元格的代码

for (int j = 0; j < matches.get(i).teams.size(); j++) {
    //gets string of team
    String teamName = matches.get(i).teams.get(j).name;

    //team names get put into multiple lines
    String teamWrapped = WordWrap.from(teamName).maxWidth(cellSize / 5).insertHyphens(true).wrap();

    //location of vertex
    int cellX = (hCellSpace / 2) + (j / rows * (cellSize + hCellSpace));
    int cellY = (titleSize) + ((j % rows) * (cellSize + vCellSpace));

    //style for vertex
    String cellStyle = "teamS;";

    //creates vertex
    Object cell = graph.insertVertex(base,null,teamWrapped,cellX,cellY,cellSize,cellStyle);
}

image of vertexes (circle shaped cells)

解决方法

style.put(mxConstants.STYLE_VERTICAL_ALIGN,"ALIGN_TOP");

然后添加 ";spacingTop=" + (cellSize + 3) 到风格

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。