Changeset 458 in tmcsimulator for trunk/src/tmcsim/client/cadclientgui/screens/UnitStatus.java
- Timestamp:
- 07/19/2019 08:14:58 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/client/cadclientgui/screens/UnitStatus.java
r445 r458 214 214 215 215 unitStatusTable.setModel(new DefaultTableModel()); 216 216 217 ((DefaultTableModel) unitStatusTable.getModel()) 217 218 .setColumnIdentifiers(TableHeaders.UNIT_STATUS_HEADERS); … … 1057 1058 if (unitStatusTable.getTableHeader().getResizingColumn() == null) 1058 1059 {//only update info if resize not in progress 1059 try 1060 { 1061 int index = unitStatusTable.getSelectedRow(); 1062 List<? extends SortKey> keys = unitStatusTable.getRowSorter().getSortKeys(); 1063 int[] columnWidths = new int[20]; 1064 for (int i = 0; i < unitStatusTable.getColumnCount(); i++) 1065 { 1066 columnWidths[i] = unitStatusTable.getColumnModel().getColumn(i).getWidth(); 1067 } 1068 1069 unitStatusTable.setModel(ScreenManager.theCoordinator.getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS)); 1070 1071 for (int i = 0; i < unitStatusTable.getColumnCount(); i++) 1072 { 1073 unitStatusTable.getColumnModel().getColumn(i).setPreferredWidth(columnWidths[i]); 1074 } 1075 unitStatusTable.getRowSorter().setSortKeys(keys); 1076 unitStatusTable.getSelectionModel().setSelectionInterval(index, index); 1077 } catch (RemoteException ex) 1078 { 1079 System.out.println("RemoteException in refreshTable method of UnitStatus.java"); 1080 System.out.println(ex.getMessage()); 1081 } 1060 1061 // Perhaps this needs to be done in Swing's Event Dispatch Thread. 1062 // See https://stackoverflow.com/questions/1732503/java-lang-arrayindexoutofboundsexception-0-0-attempting-to-populate-jtable 1063 SwingUtilities.invokeLater(new Runnable(){public void run(){ 1064 int index = unitStatusTable.getSelectedRow(); 1065 List<? extends SortKey> keys = unitStatusTable.getRowSorter().getSortKeys(); 1066 // Save column widths prior to updating table 1067 int[] columnWidths = new int[20]; 1068 for (int i = 0; i < unitStatusTable.getColumnCount(); i++) 1069 { 1070 columnWidths[i] = unitStatusTable.getColumnModel().getColumn(i).getWidth(); 1071 } 1072 //Update the model here 1073 try 1074 { 1075 // Update the table with current Coordinator data 1076 unitStatusTable.setModel(ScreenManager.theCoordinator.getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS)); 1077 } catch (RemoteException ex) 1078 { 1079 System.out.println("RemoteException in refreshTable method of UnitStatus.java"); 1080 System.out.println(ex.getMessage()); 1081 } 1082 // Set preferred column widths 1083 for (int i = 0; i < unitStatusTable.getColumnCount(); i++) 1084 { 1085 unitStatusTable.getColumnModel().getColumn(i).setPreferredWidth(columnWidths[i]); 1086 } 1087 unitStatusTable.getRowSorter().setSortKeys(keys); 1088 unitStatusTable.getSelectionModel().setSelectionInterval(index, index); 1089 }}); 1090 1082 1091 revalidate(); 1083 1092 repaint();
Note: See TracChangeset
for help on using the changeset viewer.
