Search code examples
javaswingawtburp

Java awt - get title of root window


I'm writing a plug-in for Burp Suite, and I'd like to use the current open project name in my plug-in. There is no API call for this unfortunately, so my alternative would be to take the window title and regex the project name out. The window title looks like this: enter image description here

However, I can't seem to get the title of this window using code. I've tried all of these:

SwingUtilities.windowForComponent(tab);
SwingUtilities.getWindowAncestor(tab);
SwingUtilities.getAncestorOfClass(JFrame.class, tab);
SwingUtilities.getRoot(tab);
SwingUtilities.getRootPane(tab).getParent();

Which all return: (.tostring())

burp.a_5[frame0,0,23,1280x720,invalid,layout=java.awt.BorderLayout,
title=Burp Suite Professional v2.1.03 - Temporary Project - 
licensed to OMITTED [OMITTED license],resizable,maximized,defaultCloseOperation=
DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,22,1280x698,
invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,
alignmentY=0.0,border=javax.swing.plaf.synth.SynthBorder@1a0b90f7,
flags=16777673,maximumSize=,minimumSize=,preferredSize=],
rootPaneCheckingEnabled=true]

However there seems to be no way to actually get the title= out of this object. The function .getName() returns: frame0. Maybe I'm missing something obvious. How do I get the title= out of this AWT Container object?


Solution

  • Try following:

    ((JFrame) SwingUtilities.windowForComponent(tab)).getTitle();
    

    Probably you should check whether your window is a frame or a dialog

    Window w = SwingUtilities.windowForComponent(tab);
    String title = null;
    if (w instanceof JFrame) {
        title = ((JFrame) w).getTitle();
    } else if (w instanceof JDialog) {
        title = ((JDialog) w).getTitle();
    }