Class ScaleImageLabel

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Label
com.codename1.components.ScaleImageLabel
All Implemented Interfaces:
Animation, Editable, StyleListener, IconHolder, TextHolder

public class ScaleImageLabel extends Label

Label that simplifies the usage of scale to fill/fit. This is effectively equivalent to just setting the style image on a label but more convenient for some special circumstances. One major difference is that preferred size equals the image in this case.

The default UIID for this component is "Label".

TableLayout tl = new TableLayout(2, 2);
Form hi = new Form("ScaleImageButton/Label", tl);
Style s = UIManager.getInstance().getComponentStyle("Button");
Image icon = FontImage.createMaterial(FontImage.MATERIAL_WARNING, s);
ScaleImageLabel fillLabel = new ScaleImageLabel(icon);
fillLabel.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
ScaleImageButton fillButton = new ScaleImageButton(icon);
fillButton.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
hi.add(tl.createConstraint().widthPercentage(20), new ScaleImageButton(icon)).
        add(tl.createConstraint().widthPercentage(80), new ScaleImageLabel(icon)).
        add(fillLabel).
        add(fillButton);
hi.show();
  • Constructor Details

    • ScaleImageLabel

      public ScaleImageLabel()
      Default constructor
    • ScaleImageLabel

      public ScaleImageLabel(Image i)

      Create a version with the given image

      Parameters
      • i: image
  • Method Details

    • getBackgroundType

      public byte getBackgroundType()

      Returns the background type for the component

      Returns
      Returns:
      One of Style.BACKGROUND_IMAGE_SCALED_FIT, Style.BACKGROUND_IMAGE_SCALED_FILL or Style.BACKGROUND_IMAGE_SCALE
    • setBackgroundType

      public void setBackgroundType(byte behavior)

      Sets the behavior of the background to one of Style.BACKGROUND_IMAGE_SCALED_FIT, Style.BACKGROUND_IMAGE_SCALED_FILL, Style.BACKGROUND_IMAGE_SCALE

      Parameters
      • behavior: the background behavior
    • calcPreferredSize

      protected Dimension calcPreferredSize()

      Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

      Returns

      the calculated preferred size based on component content

      Overrides:
      calcPreferredSize in class Label
    • initComponent

      protected void initComponent()

      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state

      Overriden to support animations

      Overrides:
      initComponent in class Component
    • getIcon

      public Image getIcon()

      Returns the background image

      Returns

      the bg image

      Specified by:
      getIcon in interface IconHolder
      Overrides:
      getIcon in class Label
    • setIcon

      public void setIcon(Image i)

      Instead of setting the icon sets the background image

      Parameters
      • i: the image
      Specified by:
      setIcon in interface IconHolder
      Overrides:
      setIcon in class Label
    • setText

      public void setText(String text)
      Scale image label doesn't support text this method is overriden to do nothing
      Specified by:
      setText in interface TextHolder
      Overrides:
      setText in class Label
    • setUIID

      public void setUIID(String id)

      This method sets the Component the Unique identifier. This method should be used before a component has been initialized

      Parameters
      • id: UIID unique identifier for component type

      Overriden to prevent the setUIID from replacing the code

      Overrides:
      setUIID in class Label
    • refreshTheme

      protected void refreshTheme(String id, boolean merge)
      Description copied from class: Component

      Makes sure the component is up to date with the given UIID

      Parameters
      • id: The Style Id to update the Component with

      • merge: indicates if the current styles should be merged with the new styles

      Overrides:
      refreshTheme in class Component
    • getPropertyNames

      public String[] getPropertyNames()

      A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code

      Returns

      the property names allowing mutation

      Overrides:
      getPropertyNames in class Label
    • getPropertyTypes

      public Class[] getPropertyTypes()

      Matches the property names method (see that method for further details).

      Returns

      the types of the properties

      Overrides:
      getPropertyTypes in class Label
    • getPropertyTypeNames

      public String[] getPropertyTypeNames()

      This method is here to workaround an XMLVM array type bug where property types aren't identified properly, it returns the names of the types using the following type names: String,int,double,long,byte,short,char,String[],String[][],byte[],Image,Image[],Object[],ListModel,ListCellRenderer

      Returns

      Array of type names

      Overrides:
      getPropertyTypeNames in class Label
    • getPropertyValue

      public Object getPropertyValue(String name)

      Returns the current value of the property name, this method is used by the GUI builder

      Parameters
      • name: the name of the property
      Returns

      the value of said property

      Overrides:
      getPropertyValue in class Label
    • setPropertyValue

      public String setPropertyValue(String name, Object value)

      Sets a new value to the given property, returns an error message if failed and null if successful. Notice that some builtin properties such as "$designMode" might be sent to components to indicate application state.

      Parameters
      • name: the name of the property

      • value: new value for the property

      Returns

      error message or null

      Overrides:
      setPropertyValue in class Label
    • getPreferredH

      public int getPreferredH()
      Description copied from class: Component

      Helper method to retrieve the preferred height of the component.

      Returns

      preferred height of the component

      See also
      • #getPreferredSize
      Overrides:
      getPreferredH in class Component
    • setPreferredH

      public void setPreferredH(int preferredH)
      Description copied from class: Component

      Helper method to set the preferred height of the component.

      Parameters
      • preferredH: the preferred height of the component
      Deprecated
      Overrides:
      setPreferredH in class Component
    • getPreferredW

      public int getPreferredW()
      Description copied from class: Component

      Helper method to retrieve the preferred width of the component.

      Returns

      preferred width of the component

      See also
      • #getPreferredSize
      Overrides:
      getPreferredW in class Component
    • setPreferredW

      public void setPreferredW(int preferredW)
      Description copied from class: Component

      Helper method to set the preferred width of the component.

      Parameters
      • preferredW: the preferred width of the component
      Deprecated
      Overrides:
      setPreferredW in class Component