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

  • bindingFactory.createBoundTextArea...

    Hi

    In my forms, I am using getBindingFactory().createBoundTextArea("myPropert y") to add some textArea. Sometimes I am using "rowSpan=2" or so to make it bigger.

    The problem is that the TextArea behaves differently from other fields, namely, using tab does no longer move to the next field but is an actual tab inside the TextArea.

    Is there an easy way to change this? Could or should the default component factory set the textarea that way?

    Alternatively, is there a way to have a normal String component on several rows?

    Thanks!

    Benoit
    Last edited by benoitx; Apr 2nd, 2006, 06:02 AM. Reason: more precise question...

  • #2
    This is standard Swing behaviour

    A little bit of surfing turned this link up:

    http://javaalmanac.com/egs/javax.swi...errideTab.html

    Comment


    • #3
      control-tab does what tab does in other components.

      Comment


      • #4
        Hi rdawes

        Thanks for the pointer...
        http://javaalmanac.com/egs/javax.swi...errideTab.html

        Unfortunately, I do not seem to manage to get this working...
        First of all, the snipet of code on javaalmanac would not compile due to the order of declaration and use of nextFocusAction. But that is trivial.

        I have created my own component factory that extends DefaultComponentFactory and put this code:

        Code:
            /* (non-Javadoc)
             * @see org.springframework.richclient.factory.DefaultComponentFactory#createTextArea()
             */
            @Override
            public JTextArea createTextArea() {
                final JTextArea textArea = super.createTextArea();
                changeTabActions(textArea);
                return textArea;
            }
        
            /* (non-Javadoc)
             * @see org.springframework.richclient.factory.DefaultComponentFactory#createTextArea(int, int)
             */
            @Override
            public JTextArea createTextArea(int rows, int columns) {
                final JTextArea textArea = super.createTextArea(rows, columns);
                changeTabActions(textArea);
                return textArea;
            }
            
            private void changeTabActions(final JComponent textArea) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("CHANGE TAB ACTIONS.... to textArea " + textArea+" ===========================");
                }
                // The actions
                Action nextFocusAction = new AbstractAction("Move Focus Forwards") {
                    public void actionPerformed(ActionEvent evt) {
                        ((Component)evt.getSource()).transferFocus();
                    }
                };
                Action prevFocusAction = new AbstractAction("Move Focus Backwards") {
                    public void actionPerformed(ActionEvent evt) {
                        ((Component)evt.getSource()).transferFocusBackward();
                    }
                };        
        
                // Add actions
                textArea.getActionMap().put(nextFocusAction.getValue(Action.NAME), nextFocusAction);
                textArea.getActionMap().put(prevFocusAction.getValue(Action.NAME), prevFocusAction);
            }
        I can see the code being called when I put a textArea:
        Code:
        final SwingBindingFactory bindingFactory = (SwingBindingFactory) getBindingFactory();
        TableFormBuilder formBuilder = new TableFormBuilder(bindingFactory);
        
        formBuilder.addInScrollPane(bindingFactory.createBoundTextArea("internalComment"), "rowSpan=2");
        formBuilder.row();
        ....
        Unfortunately, a TAB is still recorded as a TAB and not a jump to the next component.

        Amongst my questions, I fail to see how this snipet from javaalmanac.com links the TAB key stroke to the commands? How does it know that it should call the action rather than capturing the TAB?

        Geoffrey, the ctrl-tab works as you mentioned but it is not intuitive.

        Any suggestion?

        Thanks

        Benoit
        Last edited by benoitx; Apr 3rd, 2006, 02:28 PM.

        Comment


        • #5
          fixed!

          Well... I hate to say that but, for once, the javaalmanac.com was incomplete...

          you need to add these 2 lines:
          Code:
          component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("TAB"),
                          nextFocusAction.getValue(Action.NAME));
          
          component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("shift TAB"),
                          prevFocusAction.getValue(Action.NAME));
          And it all works.

          Let's hope that all components using textArea in Spring RC are using the ComponentFactory (i know it is not the case for other components like panel/label/buttons...)

          Thanks for the pointer

          Benoit

          Comment


          • #6
            Benoit,

            for a fairly thorough discussion on focus flow, which is what TAB characters normally control, take a look at this: http://java.sun.com/docs/books/tutor...isc/focus.html

            HTH,
            Larry.

            Comment

            Working...
            X