from java.awt import Window
# Returns the first nested component of a given class
# container = The object containing nested components to be recursively searched
# className = the __name__ of the class given as a string
def findComponentOfClass(container, className):
for component in container.components:
if component.__class__.__name__ == className:
return component
else:
foundComponent = findComponentOfClass(component, className)
if foundComponent:
return foundComponent
# Programatically open a diagnostic window, find it, and set it to the console tab
system.gui.openDiagnostics()
for window in Window.getWindows():
if window.__class__.__name__ == 'DefaultPopupWindowParent':
diagnosticDialog = findComponentOfClass(window, 'DiagnosticsDialog')
if diagnosticDialog:
tabbedPane = findComponentOfClass(diagnosticDialog, 'JTabbedPane')
tabbedPane.selectedIndex = tabbedPane.indexOfTab('Console')