FileDocCategorySizeDatePackage
Spacer.javaAPI DocJ2ME MIDP 2.06799Thu Nov 07 12:02:28 GMT 2002javax.microedition.lcdui

Spacer

public class Spacer extends Item
A blank, non-interactive item that has a settable minimum size. The minimum width is useful for allocating flexible amounts of space between Items within the same row of a Form. The minimum height is useful for enforcing a particular minimum height of a row. The application can set the minimum width or height to any non-negative value. The implementation may enforce implementation-defined maximum values for the minimum width and height.

The unlocked preferred width of a Spacer is the same as its current minimum width. Its unlocked preferred height is the same as its current minimum height.

Since a Spacer's primary purpose is to position other items, it is restricted to be non-interactive, and the application is not allowed to add Commands to a Spacer. Since the presence of a label on an Item may affect layout in device-specific ways, the label of a Spacer is restricted to always be null, and the application is not allowed to change it.

since
MIDP 2.0

Fields Summary
private int
width
The preferred (and minimum) width of this Spacer
private int
height
The preferred (and minimum) height of this Spacer
Constructors Summary
public Spacer(int minWidth, int minHeight)
Creates a new Spacer with the given minimum size. The Spacer's label is null. The minimum size must be zero or greater. If minWidth is greater than the implementation-defined maximum width, the maximum width will be used instead. If minHeight is greater than the implementation-defined maximum height, the maximum height will be used instead.

param
minWidth the minimum width in pixels
param
minHeight the minimum height in pixels
throws
IllegalArgumentException if either minWidth or minHeight is less than zero

        super(null);
        updateSizes(minWidth, minHeight);
    
Methods Summary
public voidaddCommand(Command cmd)
Spacers are restricted from having Commands, so this method will always throw IllegalStateException whenever it is called.

param
cmd the Command
throws
IllegalStateException always

        throw new IllegalStateException();
    
intcallMinimumHeight()
Get the minimum height of this Item

return
the minimum height

        return height;
    
intcallMinimumWidth()
Get the minimum width of this Item

return
the minimum width

        return width;
    
voidcallPaint(Graphics g, int w, int h)
Paint the content of this Item

param
g the Graphics object to be used for rendering the item
param
w current width of the item in pixels
param
h current height of the item in pixels

        /*
         * There's no reason to erase anything because Form will erase
         * any dirty region for us
         *
        g.setColor(Display.ERASE_COLOR);
	    g.fillRect(g.getClipX(), g.getClipY(),
                   g.getClipWidth(), g.getClipHeight());
        g.setColor(Display.FG_COLOR);
        */
    
intcallPreferredHeight(int w)
Get the preferred height of this Item

param
w the tentative content width in pixels, or -1 if a tentative width has not been computed
return
the preferred height

        return height;
    
intcallPreferredWidth(int h)
Get the preferred width of this Item

param
h the tentative content height in pixels, or -1 if a tentative height has not been computed
return
the preferred width

        return width;
    
public voidsetDefaultCommand(Command cmd)
Spacers are restricted from having Commands, so this method will always throw IllegalStateException whenever it is called.

param
cmd the Command
throws
IllegalStateException always

        throw new IllegalStateException();
    
public voidsetLabel(java.lang.String label)
Spacers are restricted to having null labels, so this method will always throw IllegalStateException whenever it is called.

param
label the label string
throws
IllegalStateException always

 
        throw new IllegalStateException();
    
public voidsetMinimumSize(int minWidth, int minHeight)
Sets the minimum size for this spacer. The Form will not be allowed to make the item smaller than this size. The minimum size must be zero or greater. If minWidth is greater than the implementation-defined maximum width, the maximum width will be used instead. If minHeight is greater than the implementation-defined maximum height, the maximum height will be used instead.

param
minWidth the minimum width in pixels
param
minHeight the minimum height in pixels
throws
IllegalArgumentException if either minWidth or minHeight is less than zero

        updateSizes(minWidth, minHeight);
    
booleanshouldSkipTraverse()
Determine if this Item should not be traversed to

return
true if this Item should not be traversed to

        return true;
    
private voidupdateSizes(int minW, int minH)
Update the width and height values of this spacer, guaranteeing the new values are positive. This method will also invalidate the containing Form.

param
minW the new width
param
minH the new height

        if (minW < 0 || minH < 0) {
             throw new IllegalArgumentException();
        }

        synchronized (Display.LCDUILock) {
            width  = minW;
            height = minH;
            invalidate();
        }