Example usage for javax.swing JPanel setFocusTraversalPolicy

List of usage examples for javax.swing JPanel setFocusTraversalPolicy

Introduction

In this page you can find the example usage for javax.swing JPanel setFocusTraversalPolicy.

Prototype

public void setFocusTraversalPolicy(FocusTraversalPolicy policy) 

Source Link

Document

Sets the focus traversal policy that will manage keyboard traversal of this Container's children, if this Container is a focus cycle root.

Usage

From source file:gdt.jgui.tool.JTextEncrypter.java

/**
 * The default constructor./*from  www . ja  v  a2s. c  o  m*/
 */
public JTextEncrypter() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    JPanel panel = new JPanel();
    panel.setBorder(
            new TitledBorder(null, "Master password", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panel);
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    JCheckBox chckbxNewCheckBox = new JCheckBox("Show");
    chckbxNewCheckBox.setHorizontalTextPosition(SwingConstants.LEFT);
    chckbxNewCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() != ItemEvent.SELECTED) {
                passwordField.setEchoChar('*');
            } else {
                passwordField.setEchoChar((char) 0);
            }
        }
    });
    panel.add(chckbxNewCheckBox);
    panel.setFocusTraversalPolicy(
            new FocusTraversalOnArray(new Component[] { chckbxNewCheckBox, passwordField }));
    passwordField = new JPasswordField();
    passwordField.setMaximumSize(new Dimension(Integer.MAX_VALUE, passwordField.getPreferredSize().height));
    panel.add(passwordField);

    JPanel panel_1 = new JPanel();
    panel_1.setBorder(new TitledBorder(null, "Text", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panel_1);
    panel_1.setLayout(new BorderLayout(0, 0));

    textArea = new JTextArea();
    textArea.setColumns(1);
    panel_1.add(textArea);

}