java.lang.Objectcom.aspose.words.PreferredWidth
public class PreferredWidth
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: Example:
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(getArtifactsDir() + "Table.PreferredWidth.doc");
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(getArtifactsDir() + "Table.CellPreferredWidths.doc");
Field Summary | ||
---|---|---|
static final PreferredWidth | AUTO | |
Returns an instance that represents the "preferred width is not specified" value. |
Property Getters/Setters Summary | ||
---|---|---|
int | getType() | |
Gets the unit of measure used for this preferred width value. The value of the property is PreferredWidthType integer constant. | ||
double | getValue() | |
Gets the preferred width value. The unit of measure is specified in the |
Method Summary | ||
---|---|---|
boolean | equals(PreferredWidth other) | |
Determines whether the specified PreferredWidth is equal in value to the current PreferredWidth. | ||
boolean | equals(java.lang.Object obj) | |
Determines whether the specified object is equal in value to the current object. | ||
static PreferredWidth | fromPercent(double percent) | |
A creation method that returns a new instance that represents a preferred width specified as a percentage. | ||
static PreferredWidth | fromPoints(double points) | |
A creation method that returns a new instance that represents a preferred width specified using a number of points. | ||
int | hashCode() | |
Serves as a hash function for this type. | ||
java.lang.String | toString() | |
Returns a user-friendly string that displays the value of this object. |
Field Detail |
---|
AUTO | |
public static final PreferredWidth AUTO |
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(getArtifactsDir() + "Table.CellPreferredWidths.doc");
Property Getters/Setters Detail |
---|
getType | |
public int getType() |
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() |
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(PreferredWidth other) |
equals | |
public boolean equals(java.lang.Object obj) |
fromPercent | |
public static PreferredWidth fromPercent(double percent) |
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(getArtifactsDir() + "Table.CellPreferredWidths.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(getArtifactsDir() + "Table.PreferredWidth.doc");
fromPoints | |
public static PreferredWidth fromPoints(double points) |
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(getArtifactsDir() + "Table.CellPreferredWidths.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() |
toString | |
public java.lang.String toString() |