Table Of Contents
- There is no Save option on this demo. How do clients handle a SAVE to update their database.
- The demo will save the changes to database as needed,
you can set the save behavior via the following methods:
ResultSetTableModel.setAutoInsertPolicy(int);
ResultSetTableModel.setAutoUpdatePolicy(int);
You can also save the changes by invoke the following method:
ResultSetTableModel.acceptChanges();
- How do I commit changes made by the user in the table to the database?
- You can invoke the methods "acceptChanges" in
ResultSetTableModel or RowSetTableModel.
- Is there an easy way to link an "end of page" in the table to fetching the next chunk of the ResultSet?
- JDataGrid Database Edition 2.5.0 and later support the feature "lazy fetch the record set".
- How to use the license code?
-
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);
- How to switch off cell selection border?
-
Use the following method in JDataGrid:
dataGrid.setSelectionBorderPainted(false);
- How to enable the column sorting in JDataGrid?
-
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.
- Whey the there is nothing (button or icon) which is displayed in the JTableHeader to allow sorting action?
-
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.
- How to enable the color effect for print preview?
-
JPrintPreview provides the following methods to enable color print preview:
JPrintPreview.setColorType(JPrintPreview.COLOR);
- Why encounter an error when add "TableColumn" in JDataGrid?
-
Please use DefaultDataGridModel.addColumn(null) to add new column in JDataGrid.
- How to set a Renderer for AComboBox that aligns the text on the left?
-
You can use the "ObjectCellRenderer" in com.zfqjava.swing.cell
directly, it has method
"setDefaultHorizontalAlignment" and
"setDefaultVerticalAlignment".
- How do I set the format of the renderer to format the date in short form:
MM/DD/YYYY?
-
You can create "DateCellRenderer" instance, it's ObjectCellRenderer
subclass, and pass a new SimpleDateFormat("MM/dd/yyyy");
- How to set a columnHeader for each column and to allow column resizing automatically?
-
The method "JDataGrid.sizeColumnWidthToFit" can size the column to fit it's contents.
- How to write a grid that is sortable and has even rows one color
and odd rows another color?
-
The JDataGrid has provide this feature since version 1.8,
you can invoke the following code:
dataGrid.setAlternatingRowBackground(Color.gray);
dataGrid.setAlternatingRowForeground(Color.white);
- Is there any way to add in a checkbox component/renderer for a table column header?
-
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);
- 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)?
-
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);
}
}
- How to sets column width of JDataGrid?
- 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);
- Why must invoke reload method in ResultSetTableModel?
- 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.
- How to set color of the even and odd row?
- 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;
}
- How to set the background area around JDataGrid?
- Should sets the background of the JDataGrid viewport, try the following code:
dataGrid.getParent().setBackground(Color.white);
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);
|
- There is no Save option on this demo. How do clients handle a SAVE to update their database.
- The demo will save the changes to database as needed,
you can set the save behavior via the following methods:
ResultSetTableModel.setAutoInsertPolicy(int);
ResultSetTableModel.setAutoUpdatePolicy(int);
You can also save the changes by invoke the following method:
ResultSetTableModel.acceptChanges();
- How do I commit changes made by the user in the table to the database?
- You can invoke the methods "acceptChanges" in
ResultSetTableModel or RowSetTableModel.
- Is there an easy way to link an "end of page" in the table to fetching the next chunk of the ResultSet?
- JDataGrid Database Edition 2.5.0 and later support the feature "lazy fetch the record set".
- How to use the license code?
-
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);
- How to switch off cell selection border?
-
Use the following method in JDataGrid:
dataGrid.setSelectionBorderPainted(false);
- How to enable the column sorting in JDataGrid?
-
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.
- Whey the there is nothing (button or icon) which is displayed in the JTableHeader to allow sorting action?
-
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.
- How to enable the color effect for print preview?
-
JPrintPreview provides the following methods to enable color print preview:
JPrintPreview.setColorType(JPrintPreview.COLOR);
- Why encounter an error when add "TableColumn" in JDataGrid?
-
Please use DefaultDataGridModel.addColumn(null) to add new column in JDataGrid.
- How to set a Renderer for AComboBox that aligns the text on the left?
-
You can use the "ObjectCellRenderer" in com.zfqjava.swing.cell
directly, it has method
"setDefaultHorizontalAlignment" and
"setDefaultVerticalAlignment".
- How do I set the format of the renderer to format the date in short form:
MM/DD/YYYY?
-
You can create "DateCellRenderer" instance, it's ObjectCellRenderer
subclass, and pass a new SimpleDateFormat("MM/dd/yyyy");
- How to set a columnHeader for each column and to allow column resizing automatically?
-
The method "JDataGrid.sizeColumnWidthToFit" can size the column to fit it's contents.
- How to write a grid that is sortable and has even rows one color
and odd rows another color?
-
The JDataGrid has provide this feature since version 1.8,
you can invoke the following code:
dataGrid.setAlternatingRowBackground(Color.gray);
dataGrid.setAlternatingRowForeground(Color.white);
- Is there any way to add in a checkbox component/renderer for a table column header?
-
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);
- 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)?
-
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);
}
}
- How to sets column width of JDataGrid?
- 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);
- Why must invoke reload method in ResultSetTableModel?
- 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.
- How to set color of the even and odd row?
- 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;
}
- How to set the background area around JDataGrid?
- Should sets the background of the JDataGrid viewport, try the following code:
dataGrid.getParent().setBackground(Color.white);
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);
|