看起来您想要将监听器注册到电子表格组件 . 为了满足您的目标,您可以将侦听器添加到它自己的电子表格对象中,或者添加到另一个实现支持添加的接口的嵌套对象 . EventListener()方法 .
以下是如何使用这些侦听器的示例 .
// Add document window listeners.
System.out.println("WriterDoc: Add window listeners.");
// Example of adding a document displose listener so the application
// can know if the user manually exits the Writer window.
document.addEventListener(new XEventListener() {
public void disposing(EventObject e) {
System.out.println(
"WriterDoc (Event Listener): The document window is closing.");
}
});
// Example of adding a window listener so the application can know
// when the document becomes initially visible (in the case of this
// implementation, we will manually set it visible below after we
// finish building it).
window.addWindowListener(new XWindowListener() {
public void windowShown(com.sun.star.lang.EventObject e) {
System.out.println(
"WriterDoc (Window listener): The document window has become visible.");
}
public void windowHidden(com.sun.star.lang.EventObject e) { }
public void disposing(com.sun.star.lang.EventObject e) { }
public void windowResized(com.sun.star.awt.WindowEvent e) { }
public void windowMoved(com.sun.star.awt.WindowEvent e) { }
});
此外,服务SheetCellRange支持XModifyBroadcaster接口 . 如果您向其注册了XModifyListener对象,也许可以获得所需的行为 . 该对象将实现'modified'方法,该方法在调用时接收EventObject . 我相信你可以从EventObject的source属性中获取调用者 . 如果源是整个SheetCellRange,您可以尝试遍历您希望监视的所有单元格,并为每个单元格添加一个XModifyListener . SheetCell服务还支持XModifyBroadcaster接口 .
干杯!