protected void restoreState ( ) { if ( store == null ) { return ; } ArrayList propColObjs = ( ArrayList ) store . getBean ( "propertyCol" , new ArrayList ( ) ) ; HidableTableColumnModel tableColumnModel = ( HidableTableColumnModel ) jtable . getColumnModel ( ) ; int newViewIndex = 0 ; for ( Object propColObj : propColObjs ) { PropertyCol propCol = ( PropertyCol ) propColObj ; try { int currentViewIndex = tableColumnModel . getColumnIndex ( propCol . getName ( ) ) ; // May throw IAE. TableColumn column = tableColumnModel . getColumn ( currentViewIndex ) ; column . setPreferredWidth ( propCol . getWidth ( ) ) ; tableColumnModel . moveColumn ( currentViewIndex , newViewIndex ) ; assert tableColumnModel . getColumn ( newViewIndex ) == column : "tableColumn wasn't successfully moved." ; // We must do this last, since moveColumn() only works on visible columns. tableColumnModel . setColumnVisible ( column , propCol . isVisible ( ) ) ; if ( propCol . isVisible ( ) ) { ++ newViewIndex ; // Don't increment for hidden columns. } } catch ( IllegalArgumentException e ) { logger . debug ( String . format ( "Column named \"%s\" was present in the preferences file but not the dataset." , propCol . getName ( ) ) , e ) ; } } }
Restore state from PreferencesExt