0

I need my vertex label displayed entirely inside vertex bounds. I mean if my label is too long then part of it will be displayed outside the vertex box. Is there any way to automatically split label into multiple lines and make it fit the vertex bounds? This line breaks should be recalculated after vertex resize. Can i do it using styles? mxUtils.wordWrap() seems to be the way but i cannot figure out how to use it properly. Give me an example of using it please. Thanks for your answers

kant
  • 157
  • 1
  • 2
  • 15
  • I've run into similar issues using swing... The solution I came up with was based around estimating the physical display length of the string (in pixels, mm, etc) and comparing that to the "vertex" bounds. If then the code discovered an 'out-of-bounds', it would choose the last location within the bounds to insert a '\n'. Is this something you think would work for your application? – Michael Apr 05 '12 at 12:52
  • yeap. thats it. I've found mxUtils.wordWrap() method and it seems to do the right thing. it splits string into string array depending on width and font metrics. but i don't konw how to use it properly. any ideas? – kant Apr 05 '12 at 13:05

1 Answers1

1

Another similar question: Calculate the display width of a string in Java

Abstract: Graphics.getFontMetrics + FontMetrics.stringWidth

From this, I suppose you could create a List<String> and add the words of the text one at a time until you reach your max length, then add a new node to the list for the overflow. Finally, append each node in the List to each other with a line break in between.

On another note, from what research I did, it seems jGraphX runs on swing. Swing now supports HTML. Here's a link to further info: http://docs.oracle.com/javase/tutorial/uiswing/components/html.html.

I will see if I can get a quick test coded up, but that must wait until I get home.

Community
  • 1
  • 1
Michael
  • 369
  • 2
  • 10