<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Swing Puzzler #1</title>
	<atom:link href="http://www.pushing-pixels.org/?feed=rss2&#038;p=1636" rel="self" type="application/rss+xml" />
	<link>http://www.pushing-pixels.org/?p=1636</link>
	<description>Leaving no pixel behind</description>
	<lastBuildDate>Wed, 01 Sep 2010 04:26:41 -0700</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Java desktop links of the week, February 21 &#124; Jonathan Giles</title>
		<link>http://www.pushing-pixels.org/?p=1636&#038;cpage=1#comment-11350</link>
		<dc:creator>Java desktop links of the week, February 21 &#124; Jonathan Giles</dc:creator>
		<pubDate>Sun, 21 Feb 2010 20:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.pushing-pixels.org/?p=1636#comment-11350</guid>
		<description>[...] Grouchnikov posted a Swing Puzzler asking what you expect following a short snippet of code. I share his sentiment about not liking [...]</description>
		<content:encoded><![CDATA[<p>[...] Grouchnikov posted a Swing Puzzler asking what you expect following a short snippet of code. I share his sentiment about not liking [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thierry Lefort</title>
		<link>http://www.pushing-pixels.org/?p=1636&#038;cpage=1#comment-11311</link>
		<dc:creator>Thierry Lefort</dc:creator>
		<pubDate>Tue, 16 Feb 2010 12:37:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.pushing-pixels.org/?p=1636#comment-11311</guid>
		<description>Great puzzler !

Reminded me from the good old days, Who said Swing backward compatibility was sometimes a real pain ;-)

Nice answer by Jeanette, as always !</description>
		<content:encoded><![CDATA[<p>Great puzzler !</p>
<p>Reminded me from the good old days, Who said Swing backward compatibility was sometimes a real pain ;-)</p>
<p>Nice answer by Jeanette, as always !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeanette Winzenburg</title>
		<link>http://www.pushing-pixels.org/?p=1636&#038;cpage=1#comment-11310</link>
		<dc:creator>Jeanette Winzenburg</dc:creator>
		<pubDate>Tue, 16 Feb 2010 12:00:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.pushing-pixels.org/?p=1636#comment-11310</guid>
		<description>Doesn&#039;t matter what the new model is (as Aekold already pointed out) - the base problem is that &quot;during self-cleanup&quot; of the table its state is more or less indeterminate. That&#039;s hard to overcome, whatever the sequence of updating the sorter/selection/ internals are. In the ol&#039; SwingX sorting we forced the selectionModel to adjusting while processing any tableEvent ... note to myself: should do so again, at least on structureChagned ;-)

Cheers
Jeanette</description>
		<content:encoded><![CDATA[<p>Doesn&#8217;t matter what the new model is (as Aekold already pointed out) &#8211; the base problem is that &#8220;during self-cleanup&#8221; of the table its state is more or less indeterminate. That&#8217;s hard to overcome, whatever the sequence of updating the sorter/selection/ internals are. In the ol&#8217; SwingX sorting we forced the selectionModel to adjusting while processing any tableEvent &#8230; note to myself: should do so again, at least on structureChagned ;-)</p>
<p>Cheers<br />
Jeanette</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ruben</title>
		<link>http://www.pushing-pixels.org/?p=1636&#038;cpage=1#comment-11309</link>
		<dc:creator>Ruben</dc:creator>
		<pubDate>Tue, 16 Feb 2010 10:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.pushing-pixels.org/?p=1636#comment-11309</guid>
		<description>The answer is: &quot;Table: 1, model: 0&quot;
It is due to the line that says: table.setAutoCreateRowSorter(true);
This line creates a TableModel that wraps the current TableModel in the table (RowSorter). Then, when you call table.getRowCount(), the table returns the row count returned by RowSorter instead of the DefaultTableModel. 
When you reset the TableModel, you are changing only the TableModel, but the table still has a RowSorter. Thats why table.getRowCount() returns a different value of table.getModel().getRowCount().
If you comment the line table.setAutoCreateRowSorter(true); the last line printed will be: &quot;Table: 0, model: 0&quot; as we expected.</description>
		<content:encoded><![CDATA[<p>The answer is: &#8220;Table: 1, model: 0&#8243;<br />
It is due to the line that says: table.setAutoCreateRowSorter(true);<br />
This line creates a TableModel that wraps the current TableModel in the table (RowSorter). Then, when you call table.getRowCount(), the table returns the row count returned by RowSorter instead of the DefaultTableModel.<br />
When you reset the TableModel, you are changing only the TableModel, but the table still has a RowSorter. Thats why table.getRowCount() returns a different value of table.getModel().getRowCount().<br />
If you comment the line table.setAutoCreateRowSorter(true); the last line printed will be: &#8220;Table: 0, model: 0&#8243; as we expected.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aekold</title>
		<link>http://www.pushing-pixels.org/?p=1636&#038;cpage=1#comment-11308</link>
		<dc:creator>Aekold</dc:creator>
		<pubDate>Tue, 16 Feb 2010 10:01:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.pushing-pixels.org/?p=1636#comment-11308</guid>
		<description>It gets obvious when looking at JTable&#039;s source code. JTable.getRowCount() takes count from RowSorter, but replacing RowSorter is very last part in setModel() method. Of course it is not good practice at all, and as for me it would be better to remove all those methods from JTable class to make everyone use MVC without compromises, but Java&#039;s backward compatibility trap will never allow it.</description>
		<content:encoded><![CDATA[<p>It gets obvious when looking at JTable&#8217;s source code. JTable.getRowCount() takes count from RowSorter, but replacing RowSorter is very last part in setModel() method. Of course it is not good practice at all, and as for me it would be better to remove all those methods from JTable class to make everyone use MVC without compromises, but Java&#8217;s backward compatibility trap will never allow it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Panos</title>
		<link>http://www.pushing-pixels.org/?p=1636&#038;cpage=1#comment-11306</link>
		<dc:creator>Panos</dc:creator>
		<pubDate>Tue, 16 Feb 2010 08:33:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.pushing-pixels.org/?p=1636#comment-11306</guid>
		<description>Should it not be 0 &amp; 0? If you reset the table model to a DefautlTableModel then it should be 0 &amp; 0, according to the javadocs

&quot;Constructs a default DefaultTableModel which is a table of zero columns and zero rows.&quot;

and (for table.getRowCount())

&quot;Returns the number of rows in this table&#039;s model. &quot;</description>
		<content:encoded><![CDATA[<p>Should it not be 0 &amp; 0? If you reset the table model to a DefautlTableModel then it should be 0 &amp; 0, according to the javadocs</p>
<p>&#8220;Constructs a default DefaultTableModel which is a table of zero columns and zero rows.&#8221;</p>
<p>and (for table.getRowCount())</p>
<p>&#8220;Returns the number of rows in this table&#8217;s model. &#8220;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirill Grouchnikov</title>
		<link>http://www.pushing-pixels.org/?p=1636&#038;cpage=1#comment-11304</link>
		<dc:creator>Kirill Grouchnikov</dc:creator>
		<pubDate>Tue, 16 Feb 2010 07:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.pushing-pixels.org/?p=1636#comment-11304</guid>
		<description>Adam,

Did you run the code with your suggested change (explicitly passing parameters to the new instance of DefaultTableModel)? I don&#039;t see any change in the results. 

Thanks
Kirill</description>
		<content:encoded><![CDATA[<p>Adam,</p>
<p>Did you run the code with your suggested change (explicitly passing parameters to the new instance of DefaultTableModel)? I don&#8217;t see any change in the results. </p>
<p>Thanks<br />
Kirill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam</title>
		<link>http://www.pushing-pixels.org/?p=1636&#038;cpage=1#comment-11301</link>
		<dc:creator>adam</dc:creator>
		<pubDate>Tue, 16 Feb 2010 07:01:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.pushing-pixels.org/?p=1636#comment-11301</guid>
		<description>It will be Table: 1, model: 0
The reason is because when you add the new DefaultTableModel you do not specify the an of the data (rows or columns) for the new TableModel and thus it is constructed with zero rows and zero columns and thus remembers the previous number of rows from a cached value in the JTable.getRowCount() I believe. This is illustrated by adding a button to add new rows of data then selecting all the rows and then adding a new TableModel. The output will be Table: , model: 0. This can be solved by changing the code to &quot;new DefaultTableModel(new Object[0][], new Object[] { &quot;Column&quot;, &quot;Names&quot; })&quot; instead of the default constructor.</description>
		<content:encoded><![CDATA[<p>It will be Table: 1, model: 0<br />
The reason is because when you add the new DefaultTableModel you do not specify the an of the data (rows or columns) for the new TableModel and thus it is constructed with zero rows and zero columns and thus remembers the previous number of rows from a cached value in the JTable.getRowCount() I believe. This is illustrated by adding a button to add new rows of data then selecting all the rows and then adding a new TableModel. The output will be Table: , model: 0. This can be solved by changing the code to &#8220;new DefaultTableModel(new Object[0][], new Object[] { &#8220;Column&#8221;, &#8220;Names&#8221; })&#8221; instead of the default constructor.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
