Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Create combox box
The example shows you how to create a combox box.
import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.Run; import com.independentsoft.office.word.WordDocument; import com.independentsoft.office.word.customMarkup.ComboBox; import com.independentsoft.office.word.customMarkup.ComboBoxListItem; import com.independentsoft.office.word.customMarkup.StructuredDocumentTag; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); StructuredDocumentTag sdt = new StructuredDocumentTag(); sdt.getProperties().setTag("Test Combox Box"); sdt.getProperties().setAlias("Test Combox Box"); ComboBoxListItem item1 = new ComboBoxListItem(); item1.setDisplayText("1"); item1.setValue("1"); ComboBoxListItem item2 = new ComboBoxListItem(); item2.setDisplayText("2"); item2.setValue("2"); ComboBoxListItem item3 = new ComboBoxListItem(); item3.setDisplayText("3"); item3.setValue("3"); sdt.getProperties().setComboBox(new ComboBox()); sdt.getProperties().getComboBox().getItems().add(item1); sdt.getProperties().getComboBox().getItems().add(item2); sdt.getProperties().getComboBox().getItems().add(item3); Run run = new Run(); run.addText("Choose an item."); Paragraph paragraph = new Paragraph(); paragraph.add(run); sdt.getContent().add(paragraph); doc.getBody().add(sdt); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*