简体   繁体   中英

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: 在此处输入图片说明

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?

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM