private TableModel createTableModel ( Object object , Set < String > excludedMethods ) { List < Method > methods = new ArrayList < Method > ( ) ; for ( Method method : object . getClass ( ) . getMethods ( ) ) { if ( ( method . getParameterTypes ( ) . length == 0 ) || ( method . getParameterTypes ( ) . length == 1 && method . getParameterTypes ( ) [ 0 ] == int . class ) ) { String name = method . getName ( ) ; if ( ! excludedMethods . contains ( name ) && ( name . startsWith ( "get" ) || name . startsWith ( "is" ) ) ) { methods . add ( method ) ; } } } Map < String , String > map = new TreeMap < String , String > ( ) ; for ( Method method : methods ) { if ( method . getParameterTypes ( ) . length == 0 ) { getSingleValue ( method , object , map ) ; } else { getMultipleValues ( method , object , map ) ; } } String [ ] headings = new String [ ] { "Property" , "Value" } ; String [ ] [ ] data = new String [ map . size ( ) ] [ 2 ] ; int rowIndex = 0 ; for ( Entry < String , String > entry : map . entrySet ( ) ) { data [ rowIndex ] [ 0 ] = entry . getKey ( ) ; data [ rowIndex ] [ 1 ] = entry . getValue ( ) ; ++ rowIndex ; } TableModel tableModel = new DefaultTableModel ( data , headings ) { @ Override public boolean isCellEditable ( int r , int c ) { return false ; } } ; return tableModel ; }
Create a table model from an object s properties .