本文整理汇总了Java中com.codename1.ui.Label.setText方法的典型用法代码示例。如果您正苦于以下问题:Java Label.setText方法的具体用法?Java Label.setText怎么用?Java Label.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.codename1.ui.Label
的用法示例。
在下文中一共展示了Label.setText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTextTransformRecursive
import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
* Sets the specified text transform to the component and all its children
*
* @param cmp The component to work on
* @param transformType The text transform type, one of the TEXT_TRANSFORM_* constants
*/
private void setTextTransformRecursive(Component cmp,int transformType) {
if (cmp instanceof Container) {
Container cont=(Container)cmp;
for(int i=0;i<cont.getComponentCount();i++) {
setTextTransformRecursive(cont.getComponentAt(i), transformType);
}
} else if (cmp instanceof Label) {
Label label=(Label)cmp;
switch(transformType) {
case TEXT_TRANSFORM_UPPERCASE:
label.setText(label.getText().toUpperCase());
break;
case TEXT_TRANSFORM_LOWERCASE:
label.setText(label.getText().toLowerCase());
break;
case TEXT_TRANSFORM_CAPITALIZE:
String text=label.getText();
String newText="";
boolean capNextLetter=true;
for(int i=0;i<text.length();i++) {
char c=text.charAt(i);
if (CSSParser.isWhiteSpace(c)) {
capNextLetter=true;
} else if (capNextLetter) {
if ((c>='a') && (c<='z')) {
c-=32; // 'A' is ASCII 65, and 'a' is ASCII 97, difference: 32
}
capNextLetter=false;
}
newText+=c;
}
label.setText(newText);
break;
}
}
}
示例2: setNowrapText
import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
* Replaces a wrapped text with an unwrapped version.
* This in fact removes all the labels that contains a single word each, and replaces them with one label that contains the whole text.
* This way the label is not wrapped.
*
* @param label The first label of this text element (can be derived from ui but already fetched before the call)
* @param ui The vector consisting all components (labels) that contain the text's words
* @param newText The new text that should replace current components (unwrapped text without extra white spaces)
* @param element The text element
*/
private void setNowrapText(Label label,Vector ui,String newText,HTMLElement element) {
label.setText(newText);
for(int i=1;i<ui.size();i++) {
Component cmp=(Component)ui.elementAt(i);
cmp.getParent().removeComponent(cmp);
}
if (label instanceof HTMLLink) {
((HTMLLink)label).childLinks=new Vector(); // Reset all associated link fragments so we don't have unneeded references
}
element.setAssociatedComponents(label);
label.getParent().revalidate();
}
示例3: handleImage
import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
* After a successful download, this handles placing the image on the label and resizing if necessary
*
* @param img The image
* @param cmp The component to apply the image on
* @param bgUnselected true if the image should be used as a background for the component when it is unselected, false otherwise
* @param bgSelected true if the image should be used as a background for the component when it is selected, false otherwise
* @param bgPressed true if the image should be used as a background for the component when it is pressed, false otherwise
*/
void handleImage(Image img,Component cmp,boolean bgUnselected,boolean bgSelected,boolean bgPressed) {
boolean bg=false;
if (bgUnselected) {
cmp.getUnselectedStyle().setBgImage(img);
bg=true;
}
if (bgSelected) {
cmp.getSelectedStyle().setBgImage(img);
bg=true;
}
if (bgPressed) {
if (cmp instanceof HTMLLink) {
((HTMLLink)cmp).getPressedStyle().setBgImage(img);
}
bg=true;
}
if (bg) {
cmp.repaint();
return;
}
Label label = (Label)cmp;
label.setText(""); // remove the alternate text (important to do here before checking the width/height)
// Was set in HTMLComponent.handleImage if the width/height attributes were in the tag
int width=label.getPreferredW()-label.getStyle().getPadding(Component.LEFT)-label.getStyle().getPadding(Component.RIGHT);
int height=label.getPreferredH()-label.getStyle().getPadding(Component.TOP)-label.getStyle().getPadding(Component.BOTTOM);
if (width!=0) {
if (height==0) { // If only width was specified, height should be calculated so the image keeps its aspect ratio
height=img.getHeight()*width/img.getWidth();
}
} else if (height!=0) {
if (width==0) { // If only height was specified, width should be calculated so the image keeps its aspect ratio
width=img.getWidth()*height/img.getHeight();
}
}
if (width!=0) { // if any of width or height were not 0, the other one was set to non-zero above, so this check suffices
img=img.scaled(width, height);
width+=label.getStyle().getPadding(Component.LEFT)+label.getStyle().getPadding(Component.RIGHT);
height+=label.getStyle().getPadding(Component.TOP)+label.getStyle().getPadding(Component.BOTTOM);
label.setPreferredSize(new Dimension(width,height));
}
label.setIcon(img);
htmlC.revalidate();
if (label.getClientProperty(HTMLComponent.CLIENT_PROPERTY_IMG_BORDER)==null) { // if this property is defined, it means the image had a border already
label.getUnselectedStyle().setBorder(null); //remove the border which is a sign the image is loading
} else {
int borderSize=((Integer)label.getClientProperty(HTMLComponent.CLIENT_PROPERTY_IMG_BORDER)).intValue();
// Note that padding is set here and not in handleImage since we rely on the image size (which includes padding) to know if a width/height was specified
label.getUnselectedStyle().setPadding(borderSize,borderSize,borderSize,borderSize);
label.getSelectedStyle().setPadding(borderSize,borderSize,borderSize,borderSize);
}
}