Package sim.util.gui
Class WordWrap
java.lang.Object
sim.util.gui.WordWrap
- All Implemented Interfaces:
Serializable
WordWrap is a simple word-wrapping class which provides word-wrap either to columns of raw text; or to some number
of pixels (given a font). It's not terribly efficient but works reasonably well. Tabs are considered to be the same length as spaces. The input is the string to wrap, and the output is the same string with returns inserted in the appropriate location.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
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 String
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 String
Wraps a string to a given number of columns.static String
wrap
(String string, int numPixels, FontMetrics metrics) Wraps a string to a given number of pixels in width, given a font whose metrics are provided as well.
-
Constructor Details
-
WordWrap
public WordWrap()
-
-
Method Details
-
wrap
Wraps a string to a given number of columns. -
wrap
Wraps a string to a given number of pixels in width, given a font whose metrics are provided as well. -
split
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. -
toHTML
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>.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>");
-