HTMLAlign class

The HTMLAlign class enables you to align sections of your HTML document, instead of just aligning individual items, say paragraphs or headings.

The HTMLAlign class represents the <DIV> tag and its associated align attribute. You can use right, left, or center alignment.

You can use this class to perform a variety of actions that include the following:

Example: Creating HTMLAlign objects

Note: Read the Code example disclaimer for important legal information.
The following example creates an unordered list, then creates an HTMLAlign object to align the entire list:
     // Create an unordered list.
     UnorderedList uList = new UnorderedList();
     uList.setType(HTMLConstants.DISC);
     UnorderedListItem uListItem1 = new UnorderedListItem();
     uListItem1.setItemData(new HTMLText("Centered unordered list"));
     uList.addListItem(uListItem1);
     UnorderedListItem uListItem2 = new UnorderedListItem();
     uListItem2.setItemData(new HTMLText("Another item"));
     uList.addListItem(uListItem2);
       
     // Align the list.
     HTMLAlign align = new HTMLAlign(uList, HTMLConstants.CENTER);
     System.out.println(align);

The previous example produces the following tag:

     <div align="center">
     <ul type="disc">
       <li>Centered unordered list</li>
       <li>Another item</li>
     </ul>

When you use this tag in an HTML page, it looks like this: