Announcement Announcement Module
Collapse
No announcement yet.
requestFocusInWindow in forms Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • requestFocusInWindow in forms

    Hi all,

    I have another question, maybe again a beginner question...

    In my project I use some forms (which extend AbstractForm). To gain the focus on a specific control, I use the requestFocusInWindow method, like shown in the samples.

    When I first open a dialog containing a form, the focus is set to the specified component. But whenever I open the dialog again, the component is not focussed anymore. By the way: I am using Spring RCP 0.2.1

    Some help or advice would be very nice.

    Thanks,

  • #2
    Does nobody have any idea?

    It would also be helpful to know how the determination of the focus (in forms, views, ...) works normally, I just can't figure out the mechanism. If I implement requestFocusInWindow in a form (derived from AbstractForm), it does not override any method in base classes. So how does the framework know it has to call requestFocusInWindow?

    Perhaps one of the developers could help here and give some explanations? Please...

    Thanks,

    Comment


    • #3
      It overrides JComponent.requestFocusInWindow().

      Comment


      • #4
        Well, AbstractForm is not a subclass of JComponent, so this can not be true. I think I have to implement the focus behaviour myself.

        Comment


        • #5
          In fact, it looks like you are expected to call requestFocusInWindow() yourself, as a convention.

          See support/src/main/java/org/springframework/richclient/security/LoginCommand.java

          Code:
                  dialog = new TitledPageApplicationDialog( tabbedPage ) {
                      protected boolean onFinish() {
                          loginForm.commit();
                          Authentication authentication = loginForm.getAuthentication();
          
                          // Hand this token to the security manager to actually attempt the login
                          ApplicationSecurityManager sm = (ApplicationSecurityManager)getService(ApplicationSecurityManager.class);
                          try {
                              sm.doLogin( authentication );
                              postLogin();
                              return true;
                          } finally {
                              if( isClearPasswordOnFailure() ) {
                                  loginForm.setPassword("");
                              }
                              loginForm.requestFocusInWindow();
                          }
                      }
          
                      protected void onCancel() {
                          super.onCancel(); // Close the dialog
          
                          // Now exit if configured
                          if( isCloseOnCancel() ) {
                              ApplicationSecurityManager sm = (ApplicationSecurityManager)getService(ApplicationSecurityManager.class);
                              Authentication authentication = sm.getAuthentication();
                              if( authentication == null ) {
                                  LoginCommand.this.logger.info( "User canceled login; close the application." );
                                  getApplication().close();
                              }
                          }
                      }
          
                      protected ActionCommand getCallingCommand() {
                          return LoginCommand.this;
                      }
          
                      protected void onAboutToShow() {
                          loginForm.requestFocusInWindow();
                      }
                  };

          Comment

          Working...
          X