Re: Problems with JTable using fixed rows
 
On Nov 3, 8:17 am, markspace <nos...@nowhere.com> wrote:
Felix Natter wrote:
hi,
I have a special table setup in order to get fixed header and footer
rows and a scrollable middle part: Three JTable (header, data, footer)
in a vertical BoxLayout which share a common TableColumnModel.
Ideally, you should post a tiny example which does the same thing as
your program, i.e., throws the exception.  It should be an SSCCE:
[truncated]
I've taken the liberty of creating an SSCCE for Felix Natter, as the
problem intrigues me.  I haven't figured it out, either.
---------- begins ----------
package cljp;
import java.awt.HeadlessException;
import javax.swing.*;
import javax.swing.table.*;
public class AppFrame extends JFrame {
public static void main(String[] args) {
    JFrame frame = new AppFrame();
    frame.setVisible(true);
}
public AppFrame() throws HeadlessException {
    super("FixedRowTable");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setSize(500, 350);
    initLayout();
}
private void initLayout() {
    Box container = new Box(BoxLayout.Y_AXIS);
    TableModel dataModel = new MyTableModel();
    TableModel headerModel = new HeaderFooterModel();
    TableModel footerModel = new HeaderFooterModel();
    JTable table = new JTable(dataModel);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    table.setAutoCreateRowSorter(true);
    JTable headerTable = new JTable(headerModel,
            table.getColumnModel());
    headerTable.setRowSelectionAllowed(false);
    JTable footer = new JTable(footerModel,
            table.getColumnModel());
    footer.setRowSelectionAllowed(false);
    container.add(headerTable);
    container.add(new JScrollPane(table));
    container.add(footer);
    getContentPane().add(container);
}
class MyTableModel extends AbstractTableModel {
    public int getRowCount() {
        return 30;
    }
    public int getColumnCount() {
        return 3;
    }
    public Object getValueAt(int rowIndex, int columnIndex) {
        return "(" + columnIndex + ", " + rowIndex + ")";
    }
}
class HeaderFooterModel extends MyTableModel {
    @Override
    public int getRowCount() {
        return 1;
    }
}
}
---------- ends ----------
If the order in which the tables are arranged in the layout is
changed, from header-table-footer to header-footer-table,
    container.add(headerTable);
    container.add(footer);
    container.add(new JScrollPane(table));
the continuous calling of getValue does not occur.