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


Java Label.setPreferredSize方法代码示例

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


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

示例1: setHeight

import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */ 
public void setHeight(int height) {
    float percent = ((float)height/(float)Display.getInstance().getDisplayHeight());
    percent *= 100;
    //if the banner height is more then 25% it's a bad ad we need to 
    //remove it.
    if(percent > 25){
        removeAll();
        Label filler = new Label(" ");
        filler.setPreferredSize(new Dimension(400, 2));
        filler.getStyle().setBgTransparency(0);
        addComponent(BorderLayout.CENTER, filler);
        revalidate();
    }else{
        super.setHeight(height);
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:20,代码来源:Ads.java

示例2: setHeight

import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */ 
public void setHeight(int height) {
    float percent = ((float)height/(float)Display.getInstance().getDisplayHeight());
    percent *= 100;
    //if the banner height is more then 25% it's a bad ad we need to 
    //remove it.
    if(percent > 25){
        removeAll();
        Label filler = new Label(" ");
        filler.setPreferredSize(new Dimension(400, 2));
        filler.getStyle().setBgTransparency(0);
        addComponent(BorderLayout.CENTER, filler);
        revalidate();
    }else{
        super.setHeight(height);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:Ads.java

示例3: Ads

import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
 * Default constructor for GUI builder
 */
public Ads() {
    setUIID("Ads");
    setLayout(new BorderLayout());
    
    // special case for iOS. It seems the ad component can inadvertedly steal focus from 
    // the text field being edited thus blocking the hiding of the lightweight text.
    // I'm guessing this can affect Android too in some cases
    setFocusable(!Display.getInstance().isTouchScreenDevice());
    Label filler = new Label(" ");
    filler.setPreferredSize(new Dimension(400, 2));
    filler.getStyle().setBgTransparency(0);
    addComponent(BorderLayout.CENTER, filler);
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:17,代码来源:Ads.java

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