public class WordWrap
extends java.lang.Object
implements java.io.Serializable
Constructor and Description |
---|
WordWrap() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
split(java.lang.String str)
A useful auxillary method: once you're word-wrapped your text, you can use this to break it into
multiple strings at the \n position.
|
static java.lang.String |
toHTML(java.lang.String text)
A useful auxillary method: once you've word-wrapped your text, you can use this to convert it into
'HTML' style, where < is converted into <, & is converted into
&, and \n or \r are converted into <br>.
|
static java.lang.String |
wrap(java.lang.String string,
int numColumns)
Wraps a string to a given number of columns.
|
static java.lang.String |
wrap(java.lang.String string,
int numPixels,
java.awt.FontMetrics metrics)
Wraps a string to a given number of pixels in width, given a font whose metrics are provided as well.
|
public static java.lang.String wrap(java.lang.String string, int numColumns)
public static java.lang.String wrap(java.lang.String string, int numPixels, java.awt.FontMetrics metrics)
public static java.lang.String[] split(java.lang.String str)
public static java.lang.String toHTML(java.lang.String text)
You can use this to make multi-line buttons and multi-line menus like this:
String myText = "Here is the big text that we want to have word-wrapped"; int myNumberOfPixels = 50; // our word-wrap pixel length JButton button = new JButton(); String wrappedText = sim.util.WordWrap.wrap(myText, myNumberOfPixels, button.getFontMetrics(button.getFont())); button.setText("<html>" + sim.util.WordWrap.toHTML(wrappedText) + "</html>");