From: Felix Natter on 2 Nov 2009 14:59 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. Now I have two problems with this: 1. resizing doesn't always work (probably related to 2.) 2. the model's getValueAt method is constantly being called, even if nothing in the JTable, not even the view, changes. This causes really high CPU load. This does not occur when I comment out the header and footer JTables. My setup is like this (Alignment means "data"): dataModel = new AlignmentDataModel(gs.getAlignment()); columnModel = new AlignmentColumnModel(gs.getAlignment()); columnModel.setColumnSelectionAllowed(false); headerTable = new JTable(new AlignmentHeaderFooterDataModel(), columnModel); headerTable.setVisible(true); headerTable.setRowHeight(22); headerTable.setRowSelectionAllowed(false); headerTable.setColumnSelectionAllowed(false); headerTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); alignmentTable = new JTable(dataModel, columnModel); // create columns and call alignmentTable.addColumn(col) // ... alignmentTable.setVisible(true); // java6... alignmentTable.setFillsViewportHeight(true); alignmentTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); alignmentTable.setRowHeight(22); alignmentTable.setRowSelectionAllowed(false); alignmentTable.setColumnSelectionAllowed(false); footerTable = new JTable(new AlignmentHeaderFooterDataModel(), columnModel); footerTable.setVisible(true); footerTable.setRowHeight(22); footerTable.setRowSelectionAllowed(false); footerTable.setColumnSelectionAllowed(false); footerTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); alignmentTable.setAutoCreateRowSorter(true); Do you have any idea what could be causing this? The multiple JTables with a common TableColumnModel seems to be a standard solution... Thanks in advance! -- Felix Natter
From: markspace on 3 Nov 2009 11:17 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: http://sscce.org/ I realize this may be difficult to construct if you have a lot of custom code, but slimming your code down will have two advantages. One, you might spot the error yourself. And two, we'll have a much better chance of finding it for you if we have an example in front of us. One row, maybe one or two columns, plus the header and footer, in a simple JPanel in a simple JFrame, then the exception should happen. If you can get that in less than 200 lines or so, we have a good chance of helping you.
From: Noel on 3 Nov 2009 14:03 On Nov 3, 8:17 am, markspace <nos...(a)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.
From: Felix Natter on 3 Nov 2009 16:45 markspace <nospam(a)nowhere.com> writes: > 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: > > http://sscce.org/ > > I realize this may be difficult to construct if you have a lot of custom > code, but slimming your code down will have two advantages. One, you might > spot the error yourself. And two, we'll have a much better chance of > finding it for you if we have an example in front of us. > > One row, maybe one or two columns, plus the header and footer, in a simple > JPanel in a simple JFrame, then the exception should happen. If you can > get that in less than 200 lines or so, we have a good chance of helping > you. Thanks for the suggestion, the simple SSCCE is attached (I know Noel posted one, but maybe it still is helpful). The problem is definitely that the data table is wrapped in a JScrollPane, and, as Noel pointed out, that the footer JTable is _below_ the data table. I tried some code from here (dummy scrollbars and such): http://www.esus.com/docs/GetQuestionPage.jsp?uid=1267 but with no success. many thanks for the help, -- Felix Natter
From: John B. Matthews on 3 Nov 2009 21:35
In article <c68a91a6-0e87-420e-9f1e-0c9abcbb7b49(a)m33g2000pri.googlegroups.com>, Noel <prosthetic_conscience1(a)yahoo.com> wrote: > On Nov 3, 8:17 am, markspace <nos...(a)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 ---------- [...] > JTable footer = new JTable(footerModel, > table.getColumnModel()); JTable footer = new JTable(footerModel, new JTable(dataModel).getColumnModel()); [...] > ---------- 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. I'm not sure why, but giving the footer it's own TableColumnModel also prevents the continual calling of getValueAt(). It's no solution, but it may suggest the underlying cause. -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews> |