我已经通过bean绑定(Netbeans)将JDialog绑定到了我的(单独的)控制器类。我的对话框有一个“关闭”按钮。此按钮的action属性绑定到控制器中的一个动作。
对话:
public class AppVersionCheckDialog extends javax.swing.JDialog {
...
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, controller, org.jdesktop.beansbinding.ELProperty.create("${closeButtonActionListener}"), btnOk, org.jdesktop.beansbinding.BeanProperty.create("action"));
bindingGroup.addBinding(binding);
...
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我得到了
public class AppVersionCheckDialogController extends AbstractController {
private final Action closeAction = new AbstractAction("Close") {
@Override
public void actionPerformed(ActionEvent e) {
// dialog.dispose() - no reference of dialog instance here
}
};
public Action getCloseButtonActionListener(){
return closeAction;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中。
我对控制器内的对话框没有任何引用。我不想介绍一个,因为它打破了将事物绑定在一起的整个原理。
那么如何关闭对话框呢?有没有办法将对话框实例绑定到控制器的属性?如果是这样,怎么办?
我现在没有编译器,但是如果我正确理解您想要的内容,则与此类似:
public void actionPerformed(ActionEvent e) {
Component component = (Component) e.getSource();
JDialog dialog = (JDialog) SwingUtilities.getRoot(component);
dialog.dispose();
}
Run Code Online (Sandbox Code Playgroud)
我将在有机会进行编译以及出现问题时进行查看。希望能解决您的问题。
| 归档时间: |
|
| 查看次数: |
2831 次 |
| 最近记录: |