Extreme Component

JDataGrid Programmer Guide > JDataGrid FAQ

JDataGrid FAQ

Q: We have a problem with PrintPreview: you can see my source code (I used some function you put in the demo) and the exception in the files I have attached.
A: I think this is not a bug, if you use the JPrintPreview in your project alone, please ensure the following class included in your classpath: JPrintPreview PrintPreviewUI BasicPrintPreviewUI XBasicLookAndFeel ModelFactory ShadowBorder icon and resources directory in the com/zfqjava/swing/plaf/basic directory You also can put the datagrid.jar in the classpath, this is the easy way to use all component in the datagrid.jar package.
Q: merge of row/column
A: As you know, the JDataGrid support merge and split cell, includes row and column.
Q: Change the column name (A,B..) (I tried "datagridmodel.setColumnName("MyString", column-index); ") but the column name doesn't change
A: I believe this is a bug, JDataGrid 1.1 have fixed this problem.
Q: Is it possible to hide the row-counter-column (I mean the column: 1,2,3.........) and how?
A: Yes, you are right, you can hide the row header, this is code:

    Component header = scrollPane.getRowHeader();
    if(header != null) {
	header.setVisible(false);
    }
    

And JDataGrid 1.1 will support this feature directly.
Q: Can I (how??) change the font / alignement for a string/cell?
A: You can change the single line string cell, but the multiple line string cell based the JTextArea component, you can change the font for multiple line string cell, but cannot change it's alignment.
Q: Can you tell me how can I set the default size for a column?
A: You can set the column size use the following code:

    int viewIndex = 1; // column index
    int value = 100; // column width
    TableColumnModel m = table.getColumnModel();
    m.getColumn(viewIndex).setPreferredWidth(value);
    

Please see the TableColumn API: setPreferredWidth for details.
Q: In your web-site I have read: "1 Source Code License" at $1797. What does it mean? You send us the source code of the library? Can we use the library for all application we will develop? (with 1 license?).
A: The 1 Source Code License includes all component source code and binary library, you can use it, modify it for the application that developed in your company, but cannot resell to other company.
Q: Row insert before index : The content of the cell clicked gets copied into the newly created row.
A: This is a selection bug, I have rewrite the selection code in JDataGrid 1.1.
Q: Delete Row/Column : A user has to keep select the cell to delete continuously
A: After rewrite and review the selection code, this problem have been solved in JDataGrid 1.1.
Q: After insert/delete column, the cell sizes of the table gets reset. It should have kept the same size.
A: Yes, you are right, this behavior is correct in JDK 1.3, but after JDK 1.4, not only the JTable clear all line height, but also clear all selection after insert and delete column.This problem have solved in JDataGrid 1.1.
Q: Cell Editing behavior change - Single Click on the cell: just focus the cell - Double Click on the cell: editing mode - JTable.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); - putClientProperty API does not work in JDataGrid model. It somehow reset this property setting. I tried with standard Swing sample program and it works fine there.
A: This problem have solved in JDataGrid 1.1.
Q: Color/Font Style changes: It only change the Style of the first cell selected not all selected cells.
A: You can disable the action "change the attributes" when select multiple cells.
Q: Implementing CRTL-Mouse CLICK to select the multiple cells I would like to have it same behavior as Excel. It does not somehow select individual cells one by one. The standard Swing application have the same problem
A: JDataGrid 1.2 have correct behavior.
Q: Disable Row Header resizing.
A: This problem has been solved JDataGrid 1.1. Please see JLineBar#setResizingAllowed(boolean) for details.
Q: Make Row/Column header clickable for insert/delete operation.
A: The JDataGrid 1.1 have implements the row and column selection when perform insert and delete, but the header clickable need different border, and the different Look And Feel have different Border, and I have implements some border, and find it is too hard to implemnts the border in the different Look And Feel, because no common API for this border, and I plan to implements a unique border and use it in the different Look And Feel.
Q: This is the ability to have a certain number of rows and columns locked when scrolling (exactly like a spreadsheet), if possible on all sides (i. e. top column headers anr buttom totals, left headers and right totals), but if ot possible at least on top and left (headers).
A: It seems that the features should be implemented through column group and row group, and current the JDataGrid component have not provide this feature, add I have use the cell merge to try, but It's not very suitable for you requirements. And may be add this feature in the future.
Q: How do we change individual cell's Background/Foreground Color and Font styles? We were not able to find APIs in your JavaDoc for this functionality.
A: As you know, change cell attributes includes font, color, etc. is not very visible. All attributes center on the setCellAttributes method on the DataGridModel. That's mean create a SimpleAttributeSet, then add some attribute on it, then put it into DataGridModel use the setCellAttributes methods. We will add some code to demonstrate the method at JDataGrid 1.1.
Q: Is it possible to have an option to enable/disable resizing the "Row Header"? (enable/disable mouse drag to resize the row header)
A: Please see JLineBar#setResizingAllowed(boolean) for details.
Q: We would like to create our own DataModel to use our Data Structure to store cell information. (eg. ArrayList[] myCells ) You have DefaultDataGridModel that extends AbstractDataGridModel that you have defined the internal data structure for the Cells. Is it possible to create our own MyDataGridModel that extends AbstractDataGridModel?
A: You can create own DataGridModel by extending the AbstractDataGridModelor extending the DefaultDataGridModel. But if you subclass the AbstractDataGridModel, the Undo and Redo and the cell merge and split should do on subclass by yourself. And I will add the bulk operations such as fill, clear, move and sort at JDataGrid 1.1, the bulk operations will avoid the unuseful firing events and can also support undo and redo.
Q: Just a single click on the cell gets into Cell Editing mode now. Is it possbile to make it behave like Excel? : a. Single Click on the cell: just focus the cell b. Double Click on the cell: editing mode
A: You can do that use the following code: dataGrid.putClientProperty("JDataGrid.clickCountToStartsEdit", new Integer(2));
Q: We have to keep select(click) the cells to deleting the row/colum continously. Is this can be fixed?
A: This have been fixed in JDataGrid 1.1.
Q: Is it possible to add(or override) more functionality in your CellRenderer/ CellEditor? If so, where and how can we do this?
A: The ObjectCellRenderer and ObjectCellEditor is ready to use and overide, and support attributes when you creating subclass.

JDataTable FAQ

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: How to set the background of the row header and column header? I have set it, but cannot work.
A: 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);  
  


Copyright (c) zfqjava.com
All rights reserved.