From cb11d18aaf4c98fb8c1a612e50cef0215855a4ef Mon Sep 17 00:00:00 2001 From: Billy Olsen Date: Tue, 9 Jun 2020 20:36:23 -0700 Subject: [PATCH] Check to see if column index is valid Check to see if column index returned from the FlightConfigurationTable model is referencing a valid column before getting the column data. Additionally, the FlightConfigurationTableModel was not adequately accounting for the FCID table column when returning the column. Fixes #677 Signed-off-by: Billy Olsen --- .../flightconfigpanel/FlightConfigurableTableModel.java | 7 ++++++- .../main/flightconfigpanel/RecoveryConfigurationPanel.java | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java index 0a83f75a7..58e3f864d 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java @@ -89,7 +89,12 @@ public class FlightConfigurableTableModel } public int getColumnIndex(FlightConfigurableComponent comp) { - return components.indexOf(comp); + int index = components.indexOf(comp); + if (index >= 0) { + // Increment the index to account for the fcid column. + index += 1; + } + return index; } @Override diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java index 9bebb3bcc..a5bbe40c3 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java @@ -83,14 +83,14 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel= 0) { + recoveryTable.getColumnModel().getColumn(index).setHeaderValue(source.getName()); + } // you would think this would be enough by itself, but it requires an nudge from the above lines to // actually update. recoveryTable.getTableHeader().resizeAndRepaint(); } }); -// recoveryTable.setColumnModel(recoveryTableModel); recoveryTable.setDefaultRenderer(Object.class, new RecoveryTableCellRenderer()); return recoveryTable;