From 58774ad05b33da76a7f73f226d189563382641a1 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Thu, 8 Jul 2021 10:32:19 +0200 Subject: [PATCH] SMACK-908: Don't use components to count tabs in Debugger Although the amount of components in a JTabbedPane apparently is often equal to the amount of tabs in it, that need not be the case. --- .../smackx/debugger/EnhancedDebuggerWindow.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java b/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java index 9822b59f9..5755207d8 100644 --- a/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java +++ b/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java @@ -140,12 +140,12 @@ public final class EnhancedDebuggerWindow { if (frame == null) { createDebug(); } - debugger.tabbedPane.setName("XMPPConnection_" + tabbedPane.getComponentCount()); - tabbedPane.add(debugger.tabbedPane, tabbedPane.getComponentCount() - 1); + debugger.tabbedPane.setName("XMPPConnection_" + tabbedPane.getTabCount()); + tabbedPane.add(debugger.tabbedPane, -1); tabbedPane.setIconAt(tabbedPane.indexOfComponent(debugger.tabbedPane), connectionCreatedIcon); tabbedPane.setSelectedIndex(tabbedPane.indexOfComponent(debugger.tabbedPane)); frame.setTitle( - "Smack Debug Window -- Total connections: " + (tabbedPane.getComponentCount() - 1)); + "Smack Debug Window -- Total connections: " + (tabbedPane.getTabCount() - 1)); // Keep the added debugger for later access debuggers.add(debugger); } @@ -286,7 +286,7 @@ public final class EnhancedDebuggerWindow { @Override public void actionPerformed(ActionEvent e) { // Remove the selected tab pane if it's not the Smack info pane - if (tabbedPane.getSelectedIndex() < tabbedPane.getComponentCount() - 1) { + if (tabbedPane.getSelectedIndex() < tabbedPane.getTabCount() - 1) { int index = tabbedPane.getSelectedIndex(); // Notify to the debugger to stop debugging EnhancedDebugger debugger = debuggers.get(index); @@ -297,7 +297,7 @@ public final class EnhancedDebuggerWindow { // Update the root window title frame.setTitle( "Smack Debug Window -- Total connections: " - + (tabbedPane.getComponentCount() - 1)); + + (tabbedPane.getTabCount() - 1)); } } }); @@ -309,7 +309,7 @@ public final class EnhancedDebuggerWindow { public void actionPerformed(ActionEvent e) { ArrayList debuggersToRemove = new ArrayList<>(); // Remove all the debuggers of which their connections are no longer valid - for (int index = 0; index < tabbedPane.getComponentCount() - 1; index++) { + for (int index = 0; index < tabbedPane.getTabCount() - 1; index++) { EnhancedDebugger debugger = debuggers.get(index); if (!debugger.isConnectionActive()) { // Notify to the debugger to stop debugging @@ -325,7 +325,7 @@ public final class EnhancedDebuggerWindow { // Update the root window title frame.setTitle( "Smack Debug Window -- Total connections: " - + (tabbedPane.getComponentCount() - 1)); + + (tabbedPane.getTabCount() - 1)); } }); menu.add(menuItem);