本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}