问题描述
当创建一个带有文本值的顶点时,它会在中间上方放置几个像素。不同的字体大小处于不同的高度。文本也小于我输入的字体大小。如何让文本居中显示在单元格中?
这是我使用的样式表。
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)
到风格