PDA

View Full Version : using CellRenderer API


fu-meng
02-03-2005, 05:07 PM
hi.

i've created a cell renderer class that should display multiple lines of text in my datagrid component. i'm pretty sure i've coded it correctly, but my text is still not being wrapped. could anyone that knows something about this take a quick look at this code and see if they spot anything?? thanks for taking a look.

fumeng.

import mx.core.UIComponent

class com.productorials.util.MultiLineCell extends UIComponent
{

// Properties
var multiLineLabel; // the label to be used for text
var owner; // the row that contains this cell
var listOwner; // the List/grid/tree that contains this cell


// Constructor
function MultiLineCell()
{
}


/* UIObject expects you to fill in createChildren by instantiating
* all the movie clip assets you might need upon initialization.
* Here, it's just a label
*/
function createChildren():Void
{
// createLabel is a useful method of UIObject--all components use this
var c = multiLineLabel = createLabel( "multiLineLabel", 10 );

// links the style of the label to the style of the grid
c.styleName = listOwner;
c.selectable = false;
c.tabEnabled = false;
c.background = false;
c.border = false;
c.multiline = true;
c.wordWrap = true;

size();
}


/* By extending UIComponent, you get setSize() for free;
* however, UIComponent expects you to implement size().
* Assume __width and __height are set for you now.
* You're going to expand the cell to fit the whole rowHeight.
*/
function size():Void
{
// __width and __height are the underlying variables
// of the getter/setters .width and .height
var c = multiLineLabel;
c._width = __width;
c._height = __height;
}


function getPreferredHeight():Number
{
/* The cell is given a property, "owner",
that references the row. It's always preferred
that the cell take up most of the row's height.
*/
return owner.__height;
}


function setValue( str:String, item:Object, sel:Boolean ):Void
{
// Set the text property of the label
// You could also set the text property to a variable.
multiLineLabel.text = "This text wraps to two lines! This text wraps to two lines! This text wraps to two lines! This text wraps to two lines! This text wraps to two lines!";
}
}

do i have to set up some properties on my datagrid as well??

fu-meng
02-03-2005, 05:33 PM
figured it out:

myDataGrid_dg.rowHeight = 80;

is this the proper fix for it, though?