Перемещение фокуса от JTextArea с помощью клавиши Tab

Проблема в width: 500% в вашем svg.

Ваш контейнер должен иметь значение width некоторого значения и margin-left & amp; margin-right из auto. Это обеспечит его центрирование.

Учитывая, что SVG не имеет своих собственных width или height, он масштабируется до 100% своего родительского контейнера.

Итак, позвольте контейнеру выполнить масштабирование, позвольте SVG масштабироваться по его контейнеру.

body {
  background: #1c222e;
  padding: 30px;
}

.c-container {
  margin: 0 auto;
}

.c-container-500 {
  max-width: 500px;
}

.c-container-100 {
  max-width: 100px;
}

Codepen

29
задан Boro 12 May 2012 в 14:05
поделиться

1 ответ

Согласно этот класс :

/**
 * Some components treat tabulator (TAB key) in their own way.
 * Sometimes the tabulator is supposed to simply transfer the focus
 * to the next focusable component.
 * <br/>
 * Here s how to use this class to override the "component's default"
 * behavior:
 * <pre>
 * JTextArea  area  = new JTextArea(..);
 * <b>TransferFocus.patch( area );</b>
 * </pre>
 * This should do the trick. 
 * This time the KeyStrokes are used.
 * More elegant solution than TabTransfersFocus().
 * 
 * @author kaimu
 * @since 2006-05-14
 * @version 1.0
 */
public class TransferFocus {

    /**
     * Patch the behaviour of a component. 
     * TAB transfers focus to the next focusable component,
     * SHIFT+TAB transfers focus to the previous focusable component.
     * 
     * @param c The component to be patched.
     */
    public static void patch(Component c) {
        Set<KeyStroke> 
        strokes = new HashSet<KeyStroke>(Arrays.asList(KeyStroke.getKeyStroke("pressed TAB")));
        c.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, strokes);
        strokes = new HashSet<KeyStroke>(Arrays.asList(KeyStroke.getKeyStroke("shift pressed TAB")));
        c.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, strokes);
    }
}

Примечание, которое patch() может быть еще короче, согласно [1 110] Joshua Goldberg в [1 111] комментарии , начиная с цели, должно возвратить поведения по умолчанию, переопределенные JTextArea:

component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERS‌​AL_KEYS, null);
component.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERS‌​AL_KEYS, null);

Это используется рассматриваемое" , Как я могу изменить поведение клавиши Tab в JTextArea? "

<час>

предыдущая реализация включенный действительно Listener, и transferFocus():

   /**
     * Override the behaviour so that TAB key transfers the focus
     * to the next focusable component.
     */
    @Override
    public void keyPressed(KeyEvent e) {
        if(e.getKeyCode() == KeyEvent.VK_TAB) {
            System.out.println(e.getModifiers());
            if(e.getModifiers() > 0) a.transferFocusBackward();
            else a.transferFocus(); 
            e.consume();
        }
    }

e.consume();, возможно, был тем, что Вы пропустили, чтобы заставить его работать в Вашем случае.

25
ответ дан Community 28 November 2019 в 02:05
поделиться
Другие вопросы по тегам:

Похожие вопросы: