Java JComponent create not focusable component

Description

Java JComponent create not focusable component

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JTextField;


class NoFocusJTextField extends JTextField {
  public NoFocusJTextField(String s) {
    super(s);//from   w  w  w . j av  a 2 s.  c  o  m
  }

  public boolean isRequestFocusEnabled() {
    return false;
  }

  public boolean isFocusTraversable() {
    return false;
  }
}

public class Main {
   public static void main(String[] argv) throws Exception {
      JTextField component = new NoFocusJTextField("www.demo2s.com");

      JFrame f = new JFrame();
      f.add(component, BorderLayout.NORTH);
      f.add(new JTextField(20), BorderLayout.SOUTH);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setSize(300, 300);
      f.setVisible(true);
   }
}



PreviousNext

Related