这个压缩包里的都是超级经典的java例子
源代码在线查看: addattr.htm
Adding an Attribute to a String (Java Developers Almanac Example)
The Java Developers Almanac 1.4
Order this book from Amazon.
google_ad_client = "pub-6001183370374757";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel = "4777242811";
google_ad_type = "text_image";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "6666CC";
google_color_url = "6666CC";
google_color_text = "000000";
//-->
Home
>
List of Packages
>
java.text
[26 examples]
e308. Adding an Attribute to a String
Some applications need to mark a range of characters in a string with
an attribute, such as a color. The AttributedString class is a
wrapper for a string that provides support for marking ranges of
characters with an attribute. An attribute consists of a name, a
value, and a contiguous range of characters on which the attribute
applies.
This example marks a word in a string with the attribute called
color and the value red.
// Declare an attribute name.
// An attribute name is an object that extends AttributedCharacterIterator.Attribute.
// Author's note: A more appropriate name would be AttributedCharacterIterator.AttributeName
static final AttributedCharacterIterator.Attribute COLOR
= new AttributedCharacterIterator.Attribute("color") {
};
// Create the attributed string
AttributedString astr = new AttributedString("the hot pot");
// Add the COLOR attribute on the word `hot'
astr.addAttribute(COLOR, "Red", 4, 7);
Related Examples
e305.
Determining the Type of a Character
e306.
Comparing Strings in a Locale-Independent Way
e307.
Iterating the Characters of a String
e309.
Incrementing a Double by the Smallest Possible Amount
e310.
Localizing Messages
See also:
Dates
Messsages
Numbers
Times
Words and Sentences
© 2002 Addison-Wesley.