当前位置: 首页>>代码示例>>Java>>正文


Java Label.setIcon方法代码示例

本文整理汇总了Java中com.codename1.ui.Label.setIcon方法的典型用法代码示例。如果您正苦于以下问题:Java Label.setIcon方法的具体用法?Java Label.setIcon怎么用?Java Label.setIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.codename1.ui.Label的用法示例。


在下文中一共展示了Label.setIcon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRendererContainer

import com.codename1.ui.Label; //导入方法依赖的package包/类
private Container createRendererContainer() {
    Container entries = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    entries.setUIID("RSSEntry");
    Label title = new Label();
    title.setName("title");
    title.setUIID("RSSTitle");
    entries.addComponent(title);
    TextArea description = new TextArea(2, 30);
    description.setGrowByContent(false);
    description.setName("details");
    description.setUIID("RSSDescription");
    description.setScrollVisible(false);
    entries.addComponent(description);
    if(iconPlaceholder != null) {
        Container wrap = new Container(new BorderLayout());
        wrap.addComponent(BorderLayout.CENTER, entries);
        Label icon = new Label();
        icon.setIcon(iconPlaceholder);
        icon.setUIID("RSSIcon");
        icon.setName("icon");
        wrap.addComponent(BorderLayout.WEST, icon);
        entries = wrap;
    }
    return entries;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:26,代码来源:RSSReader.java

示例2: UserForm

import com.codename1.ui.Label; //导入方法依赖的package包/类
public UserForm(String name, EncodedImage placeHolder, String imageURL) {
    this.name = name;
    this.imageURL = imageURL;
    setTitle("Welcome!");
    setLayout(new BorderLayout());
    
    Label icon = new Label(placeHolder);
    icon.setUIID("Picture");
    if(imageURL != null){
        icon.setIcon(URLImage.createToStorage(placeHolder, name, imageURL, null));
    }
    addComponent(BorderLayout.CENTER, icon);
    Label nameLbl = new Label(name);
    nameLbl.setUIID("Name");
    addComponent(BorderLayout.SOUTH, nameLbl);
    final Form current = Display.getInstance().getCurrent();
    Command back = new Command("Back"){

        @Override
        public void actionPerformed(ActionEvent evt) {
            current.showBack();;
        }

    };
    addCommand(back);
    setBackCommand(back);
    
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:29,代码来源:UserForm.java

示例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);
    }

}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:68,代码来源:ResourceThreadQueue.java


注:本文中的com.codename1.ui.Label.setIcon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。