com.aspose.words
Class PreferredWidth

java.lang.Object
    extended by com.aspose.words.PreferredWidth

public class PreferredWidth 
extends java.lang.Object

Represents a value and its unit of measure that is used to specify the preferred width of a table or a cell.

Preferred width can be specified as a percentage, number of points or a special "none/auto" value.

The instances of this class are immutable.

Example:

Shows how to set a table to auto fit to 50% of the page width.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a table with a width that takes up half the page width.
Table table = builder.startTable();

// Insert a few cells
builder.insertCell();
table.setPreferredWidth(PreferredWidth.fromPercent(50));
builder.writeln("Cell #1");

builder.insertCell();
builder.writeln("Cell #2");

builder.insertCell();
builder.writeln("Cell #3");

doc.save(getMyDir() + "Table.PreferredWidth Out.doc");

Example:

Shows how to set the different preferred width settings.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a table row made up of three cells which have different preferred widths.
Table table = builder.startTable();

// Insert an absolute sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(40));
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.RED);
builder.writeln("Cell at 40 points width");

// Insert a relative (percent) sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(20));
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.BLUE);
builder.writeln("Cell at 20% width");

// Insert a auto sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.AUTO);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
builder.writeln("Cell automatically sized. The size of this cell is calculated from the table preferred width.");
builder.writeln("In this case the cell will fill up the rest of the available space.");

doc.save(getMyDir() + "Table.PreferredWidths Out.doc");
See Also:
RowFormat.PreferredWidth, CellFormat.PreferredWidth

Field Summary
static final PreferredWidthAUTO
           Returns an instance that represents the "preferred width is not specified" value.
 
Property Getters/Setters Summary
intgetType()
           Gets the unit of measure used for this preferred width value. The value of the property is PreferredWidthType integer constant.
doublegetValue()
           Gets the preferred width value. The unit of measure is specified in the Type property.
 
Method Summary
booleanequals(java.lang.Object obj)
           Determines whether the specified object is equal in value to the current object.
static PreferredWidthfromPercent(double percent)
           A creation method that returns a new instance that represents a preferred width specified as a percentage.
static PreferredWidthfromPoints(double points)
           A creation method that returns a new instance that represents a preferred width specified using a number of points.
inthashCode()
           Serves as a hash function for this type.
java.lang.StringtoString()
           Returns a user-friendly string that displays the value of this object.
 

Field Detail

AUTO

public static final PreferredWidth AUTO
Returns an instance that represents the "preferred width is not specified" value.

Example:

Shows how to set the different preferred width settings.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a table row made up of three cells which have different preferred widths.
Table table = builder.startTable();

// Insert an absolute sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(40));
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.RED);
builder.writeln("Cell at 40 points width");

// Insert a relative (percent) sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(20));
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.BLUE);
builder.writeln("Cell at 20% width");

// Insert a auto sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.AUTO);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
builder.writeln("Cell automatically sized. The size of this cell is calculated from the table preferred width.");
builder.writeln("In this case the cell will fill up the rest of the available space.");

doc.save(getMyDir() + "Table.PreferredWidths Out.doc");

Property Getters/Setters Detail

getType

public int getType()
Gets the unit of measure used for this preferred width value. The value of the property is PreferredWidthType integer constant.

Example:

Retrieves the preferred width type of a table cell.
Cell firstCell = table.getFirstRow().getFirstCell();
int type = firstCell.getCellFormat().getPreferredWidth().getType();
double value = firstCell.getCellFormat().getPreferredWidth().getValue();

getValue

public double getValue()
Gets the preferred width value. The unit of measure is specified in the Type property.

Example:

Retrieves the preferred width type of a table cell.
Cell firstCell = table.getFirstRow().getFirstCell();
int type = firstCell.getCellFormat().getPreferredWidth().getType();
double value = firstCell.getCellFormat().getPreferredWidth().getValue();

Method Detail

equals

public boolean equals(java.lang.Object obj)
Determines whether the specified object is equal in value to the current object.

fromPercent

public static PreferredWidth fromPercent(double percent)
A creation method that returns a new instance that represents a preferred width specified as a percentage.
Parameters:
percent - The value must be from 0 to 100.

Example:

Shows how to set the different preferred width settings.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a table row made up of three cells which have different preferred widths.
Table table = builder.startTable();

// Insert an absolute sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(40));
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.RED);
builder.writeln("Cell at 40 points width");

// Insert a relative (percent) sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(20));
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.BLUE);
builder.writeln("Cell at 20% width");

// Insert a auto sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.AUTO);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
builder.writeln("Cell automatically sized. The size of this cell is calculated from the table preferred width.");
builder.writeln("In this case the cell will fill up the rest of the available space.");

doc.save(getMyDir() + "Table.PreferredWidths Out.doc");

Example:

Shows how to set a table to auto fit to 50% of the page width.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a table with a width that takes up half the page width.
Table table = builder.startTable();

// Insert a few cells
builder.insertCell();
table.setPreferredWidth(PreferredWidth.fromPercent(50));
builder.writeln("Cell #1");

builder.insertCell();
builder.writeln("Cell #2");

builder.insertCell();
builder.writeln("Cell #3");

doc.save(getMyDir() + "Table.PreferredWidth Out.doc");

fromPoints

public static PreferredWidth fromPoints(double points)
A creation method that returns a new instance that represents a preferred width specified using a number of points.
Parameters:
points - The value must be from 0 to 22 inches (22 * 72 points).

Example:

Shows how to set the different preferred width settings.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a table row made up of three cells which have different preferred widths.
Table table = builder.startTable();

// Insert an absolute sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(40));
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.RED);
builder.writeln("Cell at 40 points width");

// Insert a relative (percent) sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(20));
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.BLUE);
builder.writeln("Cell at 20% width");

// Insert a auto sized cell.
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.AUTO);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
builder.writeln("Cell automatically sized. The size of this cell is calculated from the table preferred width.");
builder.writeln("In this case the cell will fill up the rest of the available space.");

doc.save(getMyDir() + "Table.PreferredWidths Out.doc");

Example:

Shows how to specify a cell preferred width by converting inches to points.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(ConvertUtil.inchToPoint(3)));
builder.insertCell();

hashCode

public int hashCode()
Serves as a hash function for this type.

toString

public java.lang.String toString()
Returns a user-friendly string that displays the value of this object.

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.