| Show all answer |
| Q: How to use the license code? |
A: You can input it on the "About" dialog. You can also use the following code to register the license code in your programming code: // the code means the above license data LicenseManager.getInstance().addLicenseData(code); |
| Q: How to switch off cell selection border? |
A: Use the following method in JDataGrid: dataGrid.setSelectionBorderPainted(false); |
| Q: How to enable the column sorting in JDataGrid? |
A: You should enable the following client property in JDataGrid: dataGrid.setModel(new DefaultColumnSorter(createModel())); dataGrid.putClientProperty("JDataGrid.columnSortingEnabled", Boolean.TRUE); dataGrid.putClientProperty("JDataGrid.switchUnsortedOrderEnabled", Boolean.TRUE); And you should use the default JTableHeader build-in JDataGrid. |
| Q: Whey the there is nothing (button or icon) which is displayed in the JTableHeader to allow sorting action? |
A: You should use the default JTableHeader build-in JDataGrid, Because the default JTableHeader cannot provide the support for column sorting, it have not this feature, such as show a arrow icon, or act as a button pushing. |
| Q: How to enable the color effect for print preview? |
A: JPrintPreview provides the following methods to enable color print preview: JPrintPreview.setColorType(JPrintPreview.COLOR); |
| Q: Why encounter an error when add "TableColumn" in JDataGrid? |
A: Please use DefaultDataGridModel.addColumn(null) to add new column in JDataGrid. |
| Q: How to set a Renderer for AComboBox that aligns the text on the left? |
A: You can use the "ObjectCellRenderer" in com.zfqjava.swing.cell
directly, it has method "setDefaultHorizontalAlignment" and "setDefaultVerticalAlignment". |
| Q: How do I set the format of the renderer to format the date in short
form: MM/DD/YYYY? |
A: You can create "DateCellRenderer" instance, it's ObjectCellRenderer
subclass, and pass a new SimpleDateFormat("MM/dd/yyyy"); |
| Q: How to set a columnHeader for each column and to allow column resizing automatically? |
A: The method "JDataGrid.sizeColumnWidthToFit" can size the column to fit it's contents. |
| Q: The formula cannot work with OpenOffice, how to modified the code? |
A: A: We have add new API in FormulaFactory, you can switch from Excel formula syntax to OpenOffice formula syntax easily, you
can try the following API: FormulaFactory.setArgumentSeparatorChar(';'); |
| Q: How to write a grid that is sortable and has even rows one color and odd rows another color? |
A: The JDataGrid has provide this feature since version 1.8, you can invoke the following code: dataGrid.setAlternatingRowBackground(Color.gray); dataGrid.setAlternatingRowForeground(Color.white); |
| Q: Is there any way to add in a checkbox component/renderer for a table column header? |
A: The following code enable the checkbox in JDataGrid table header: JDataGrid dataGrid = getDataGrid(); BooleanCellRenderer renderer = new BooleanCellRenderer(); renderer.setComponentType(BooleanCellRenderer.CHECK_BOX); // gloablly enable the check box renderer // dataGrid.getTableHeader().setDefaultRenderer(renderer); dataGrid.getColumnModel().getColumn(0).setHeaderRenderer(renderer); |
| Q:Is it possible to prevent a single column from being moved? I have a list of columns that the user can move, but I want the first column to stay the first column (not freezing a column or window)? |
A: This function can be implemented by write a
customize TableColumnModel, override the method: TableColumn firstColumn = new TableColumn(0); // override the method in TableColumnModel public TableColumn getColumn(int columnIndex) { if(columnIndex == 0) { return firstColumn; } else { return super.getColumn(columnIndex); } } |
| Q: How to enable the JDataGrid convert the number cell to normal cell when the value is illegal number? |
A: Use the following code: dataGrid.setEditingStopBehavior(JDataGrid.COMMIT_OR_EDITING); |
| Q: How to set a row height when export to xls file from DataGridModel? |
A: Use the following code to set a row height to worksheet: WorkSheet[] sheets = new WorkSheet[1]; sheets[0] = new WorkSheet("sheet0", tableModel); // add the following code: SizeModel rowSizeModel = new DefaultSizeModel("row model", tableModel.getRowCount(), 16); rowSizeModel.setSize(0, 30); sheets[0].setRowSizeModel(rowSizeModel); WorkBook book = new WorkBook(sheets); ModelIO.writeWorkBook(book, "xls", null, f); |
| >>Old FAQ Documentation |