Results 1 to 6 of 6

Thread: bindingFactory.createBoundTextArea...

  1. #1
    Join Date
    Aug 2005
    Location
    London (the English one!)
    Posts
    378

    Default 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 at 05:02 AM. Reason: more precise question...

  2. #2
    Join Date
    Feb 2006
    Posts
    118

    Default This is standard Swing behaviour

    A little bit of surfing turned this link up:

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

  3. #3
    Join Date
    May 2005
    Posts
    394

    Default

    control-tab does what tab does in other components.

  4. #4
    Join Date
    Aug 2005
    Location
    London (the English one!)
    Posts
    378

    Default

    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 at 01:28 PM.

  5. #5
    Join Date
    Aug 2005
    Location
    London (the English one!)
    Posts
    378

    Default 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

  6. #6
    Join Date
    Aug 2005
    Location
    Austin, TX
    Posts
    425

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •