| Q: | How to sets column width of JDataGrid? |
| A: | The JDataGrid provides this feature directly since 1.2, try the following code to set JDataGrid column width: JDataGrid dataGrid = createDataGrid(); // set the default column width dataGrid.setColumnWidth(100); // set the column width at the specified column dataGrid.setColumnWidth(2, 200); |
| Q: | Why must invoke reload method in ResultSetTableModel? |
| A: | The ResultTableTableModel is loading data in background thread, invoke reload method will start the background thread and then loading data from data source, the will give a chance for set it to JDataGrid. |
| Q: | How to set color of the even and odd row? |
| A: | Overide the JDataGrid and add the following code: public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); if(row % 2 == 0) { // even row c.setBackground(Color.gray); } else { // odd row c.setBackground(Color.white); } return c; } > |
| Q: | How to set the background area around JDataGrid? |
| A: | Should sets the background of the JDataGrid viewport, try the following code: dataGrid.getParent().setBackground(Color.white); |
| Q: | You should set the background and it's viewport background of the row header or column header both, try the following code: JDataGrid dataGrid = createDataGrid(); JScrollPane scrollPane = new JScrollPane(dataGrid); // ensure the row header and column header have add into JScrollPane scrollPane.setRowHeaderView(dataGrid.getRowHeader()); scrollPane.setColumnHeaderView(dataGrid.getTableHeader()); // set the background of the datagrid dataGrid.getRowHeader().setBackground(Color.white); dataGrid.getRowHeader().getParent().setBackground(Color.white); dataGrid.getTableHeader().setBackground(Color.white); dataGrid.getTableHeader().getParent().setBackground(Color.white); |