@Test public void testSetWidthRange() { WTableColumn col = new WTableColumn("width2", WText.class); col.setWidth(-1); Assert.assertEquals("Incorrect width percentage from setter -1", 0, col.getWidth()); col.setWidth(0); Assert.assertEquals("Incorrect width percentage from setter 0", 0, col.getWidth()); col.setWidth(100); Assert.assertEquals("Incorrect width percentage from setter 100", 100, col.getWidth()); }
@Test(expected = IllegalArgumentException.class) public void testSetWidthInvalidGreater100() { WTableColumn col = new WTableColumn("width3", WText.class); col.setWidth(101); }
/** * Create example. */ public WTableColumnWidthExample() { add(table); table.setSeparatorType(WTable.SeparatorType.VERTICAL); // Columns WTableColumn columnFName = new WTableColumn("First name (40%)", new WText()); WTableColumn columnSName = new WTableColumn("Last name (45%)", new WText()); WTableColumn columnDoB = new WTableColumn("DOB (15%)", new WText()); columnFName.setWidth(40); columnSName.setWidth(45); columnDoB.setWidth(15); table.addColumn(columnFName); table.addColumn(columnSName); table.addColumn(columnDoB); // Set the "basic" data String[][] data = ExampleDataUtil.createBasicData(); BasicTableModel model = new SimpleTableModel(data); // Set the model on the table via the adapter table.setTableModel(new AdapterBasicTableModel(model)); }
@Test public void testDoPaintWithColWidth() throws IOException, SAXException, XpathException { WTable table = new WTable(); table.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class)); table.getColumn(0).setWidth(0); table.getColumn(1).setWidth(1); table.getColumn(2).setWidth(100); TableModel tableModel = createTableModel(); table.setTableModel(tableModel); assertXpathNotExists("//ui:table/ui:thead/ui:th[1]/@width", table); assertXpathEvaluatesTo("1", "//ui:table/ui:thead/ui:th[2]/@width", table); assertXpathEvaluatesTo("100", "//ui:table/ui:thead/ui:th[3]/@width", table); }
@Test public void testDoPaintWithColWidth() throws IOException, SAXException, XpathException { WDataTable table = new WDataTable(); table.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class)); table.getColumn(0).setWidth(0); table.getColumn(1).setWidth(1); table.getColumn(2).setWidth(100); TableDataModel tableModel = createTableModel(); table.setDataModel(tableModel); assertXpathNotExists("//ui:table/ui:thead/ui:th[1]/@width", table); assertXpathEvaluatesTo("1", "//ui:table/ui:thead/ui:th[2]/@width", table); assertXpathEvaluatesTo("100", "//ui:table/ui:thead/ui:th[3]/@width", table); }
label.setIdName("col_action"); WTableColumn column = new WTableColumn(label, actionContainer); column.setWidth(5); table.addColumn(column); setUpActionButtons();