When user moves cursor over a link, Chromium engine displays its URL in status bar. JavaScript code can change text in status bar programmatically via window.status property as well. JxBrowser API provides functionality that allows you to get notifications about status bar text changes. The following sample demonstrates how to use this functionality:(当用户将光标移到链接上时,Chromium引擎会在状态栏中显示其URL。 JavaScript代码也可以通过window.status属性以编程方式更改状态栏中的文本。 JxBrowser API提供的功能使您可以获取有关状态栏文本更改的通知。下面的示例演示如何使用此功能:)
import com.teamdev.jxbrowser.chromium.Browser; import com.teamdev.jxbrowser.chromium.LoggerProvider; import com.teamdev.jxbrowser.chromium.events.StatusEvent; import com.teamdev.jxbrowser.chromium.events.StatusListener; import com.teamdev.jxbrowser.chromium.swing.BrowserView; import javax.swing.*; import java.awt.*; import java.util.logging.Level; /** * The sample demonstrates how to listen to status change events. */ public class StatusListenerSample { public static void main(String[] args) { LoggerProvider.getIPCLogger().setLevel(Level.SEVERE); Browser browser = new Browser(); BrowserView browserView = new BrowserView(browser); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(browserView, BorderLayout.CENTER); frame.setSize(800, 600); frame.setLocationRelativeTo(null); frame.setVisible(true); browser.addStatusListener(new StatusListener() { public void onStatusChange(StatusEvent event) { System.out.println("Text = " + event.getText()); } }); browser.loadURL("http://www.google.com"); } }