Java 类java.awt.TextField 实例源码

项目:openjdk-jdk10    文件:DeadKeySystemAssertionDialog.java   
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        frame.setVisible(true);
        robot.waitForIdle();

        textField.requestFocus();
        robot.waitForIdle();

        // Check that the system assertion dialog does not block Java
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.waitForIdle();

        frame.setVisible(false);
        frame.dispose();
    }
项目:jdk8u-jdk    文件:SelectionInvisibleTest.java   
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        frame.setSize(300, 200);
        TextField textField = new TextField(TEXT + LAST_WORD, 30);
        Panel panel = new Panel(new FlowLayout());
        panel.add(textField);
        frame.add(panel);
        frame.setVisible(true);

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        toolkit.realSync();

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Point point = textField.getLocationOnScreen();
        int x = point.x + textField.getWidth() / 2;
        int y = point.y + textField.getHeight() / 2;
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        robot.mousePress(InputEvent.BUTTON1_MASK);
        int N = 10;
        int dx = textField.getWidth() / N;
        for (int i = 0; i < N; i++) {
            x += dx;
            robot.mouseMove(x, y);
        }
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        if (!textField.getSelectedText().endsWith(LAST_WORD)) {
            throw new RuntimeException("Last word is not selected!");
        }
    }
项目:jdk8u-jdk    文件:SelectionVisible.java   
@Override
public void init() {
    tf = new TextField(20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                     + "The text 012345 should be selected in the TextField.\n"
                                     + "If this is what you observe, then the test passes.\n"
                                     + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
项目:jdk8u-jdk    文件:DeadKeySystemAssertionDialog.java   
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
项目:openjdk-jdk10    文件:DisabledUndoTest.java   
public static void initTestWindow() {
    mainFrame = new Frame();
    p1 = new Panel();
    mainFrame.setTitle("TestWindow");
    mainFrame.setBounds(700, 10, 400, 100);

    tf = new TextField(20);
    tf.select(0, 10);
    bt = new Button("Disable textfield");
    p1.add(tf);
    p1.add(bt);
    mainFrame.add(p1);
    bt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            tf.setEditable(false);
        }
    });
    mainFrame.setVisible(true);
}
项目:openjdk-jdk10    文件:OverScrollTest.java   
OverScrollTest() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage());
    }

    mainFrame = new Frame();
    mainFrame.setSize(400, 200);
    mainFrame.setLocation(200, 200);
    mainFrame.setLayout(new FlowLayout());

    textField = new TextField(10);
    textField.setSize(300, 100);
    textField.setText("123456 789123");
    mainFrame.add(textField);
    mainFrame.setVisible(true);
    textField.requestFocusInWindow();
}
项目:openjdk-jdk10    文件:SelectionVisible.java   
@Override
public void init() {
    tf = new TextField(20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                     + "The text 012345 should be selected in the TextField.\n"
                                     + "If this is what you observe, then the test passes.\n"
                                     + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
项目:openjdk-jdk10    文件:MultiResolutionSplashTest.java   
static void testFocus() throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();

        if (!textField.getText().equals("ab")) {
            throw new RuntimeException("Focus is lost!");
        }
    }
项目:openjdk-jdk10    文件:UnixMultiResolutionSplashTest.java   
static void testFocus() throws Exception {

        System.out.println("Focus Test!");
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();
        if (!textField.getText().equals("ab")) {
            throw new RuntimeException("Focus is lost!");
        }
    }
项目:openjdk9    文件:OverScrollTest.java   
OverScrollTest() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage());
    }

    mainFrame = new Frame();
    mainFrame.setSize(400, 200);
    mainFrame.setLocation(200, 200);
    mainFrame.setLayout(new FlowLayout());

    textField = new TextField(10);
    textField.setSize(300, 100);
    textField.setText("123456 789123");
    mainFrame.add(textField);
    mainFrame.setVisible(true);
    textField.requestFocusInWindow();
}
项目:openjdk9    文件:SelectionVisible.java   
@Override
public void init() {
    tf = new TextField(20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                     + "The text 012345 should be selected in the TextField.\n"
                                     + "If this is what you observe, then the test passes.\n"
                                     + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
项目:openjdk9    文件:UnixMultiResolutionSplashTest.java   
static void testFocus() throws Exception {

        System.out.println("Focus Test!");
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();
        if (!textField.getText().equals("ab")) {
            throw new RuntimeException("Focus is lost!");
        }
    }
项目:openjdk9    文件:DeadKeySystemAssertionDialog.java   
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        frame.setVisible(true);
        robot.waitForIdle();

        textField.requestFocus();
        robot.waitForIdle();

        // Check that the system assertion dialog does not block Java
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.waitForIdle();

        frame.setVisible(false);
        frame.dispose();
    }
项目:OpenNFMM    文件:StageMaker.java   
private void fixtext(final TextField textfield) {
    String string = textfield.getText();
    string = string.replace('\"', '#');
    final String string330 = "\\";
    String string331 = "";
    int i = 0;
    int i332 = -1;
    rd.setFont(new Font("Arial", 1, 12));
    ftm = rd.getFontMetrics();
    for (/**/; i < string.length(); i++) {
        final String string333 = "" + string.charAt(i);
        if (string333.equals("|") || string333.equals(",") || string333.equals("(") || string333.equals(")") || string333.equals("#") || string333.equals(string330) || string333.equals("!") || string333.equals("?") || string333.equals("~") || string333.equals(".") || string333.equals("@") || string333.equals("$") || string333.equals("%") || string333.equals("^") || string333.equals("&") || string333.equals("*") || string333.equals("+") || string333.equals("=") || string333.equals(">") || string333.equals("<") || string333.equals("/") || string333.equals(";") || string333.equals(":") || ftm.stringWidth(string331) > 274) {
            i332 = i;
        } else {
            string331 = "" + string331 + string333;
        }
    }
    if (i332 != -1) {
        textfield.setText(string331);
        textfield.select(i332, i332);
    }
}
项目:OpenNFMM    文件:Login.java   
private void fixtext(final TextField textfield) {
    String string = textfield.getText();
    string = string.replace('\"', '#');
    final String string64 = "\\";
    String string65 = "";
    int i = 0;
    int i66 = -1;
    for (/**/ ; i < string.length(); i++) {
        final String string67 = "" + string.charAt(i);
        if (string67.equals("|") || string67.equals(",") || string67.equals("(") || string67.equals(")") || string67.equals("#") || string67.equals(string64) || string67.equals("!") || string67.equals("?") || string67.equals(" ") || string67.equals("~") || string67.equals("$") || string67.equals("%") || string67.equals("^") || string67.equals("&") || string67.equals("*") || string67.equals("+") || string67.equals("=") || string67.equals(">") || string67.equals("<") || string67.equals("/") || string67.equals("'") || string67.equals(";") || string67.equals(":") || string67.equals("\u00a0")) {
            i66 = i;
        } else {
            string65 = "" + string65 + string67;
        }
    }
    if (i66 != -1) {
        textfield.setText(string65);
        textfield.select(i66, i66);
    }
}
项目:OpenNFMM    文件:CarMaker.java   
private void fixtext(final TextField textfield) {
    String string = textfield.getText();
    string = string.replace('\"', '#');
    final String string360 = "\\";
    String string361 = "";
    int i = 0;
    int i362 = -1;
    for (/**/; i < string.length(); i++) {
        final String string363 = "" + string.charAt(i);
        if (string363.equals("|") || string363.equals(",") || string363.equals("(") || string363.equals(")") || string363.equals("#") || string363.equals(string360) || string363.equals("!") || string363.equals("?") || string363.equals("~") || string363.equals(".") || string363.equals("@") || string363.equals("$") || string363.equals("%") || string363.equals("^") || string363.equals("&") || string363.equals("*") || string363.equals("+") || string363.equals("=") || string363.equals(">") || string363.equals("<") || string363.equals("/") || string363.equals("'") || string363.equals(";") || string363.equals(":") || i > 15) {
            i362 = i;
        } else {
            string361 = "" + string361 + string363;
        }
    }
    if (i362 != -1) {
        textfield.setText(string361);
        textfield.select(i362, i362);
    }
}
项目:jdk8u_jdk    文件:SelectionVisible.java   
@Override
public void init() {
    tf = new TextField(20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                     + "The text 012345 should be selected in the TextField.\n"
                                     + "If this is what you observe, then the test passes.\n"
                                     + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
项目:jdk8u_jdk    文件:DeadKeySystemAssertionDialog.java   
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
项目:lookaside_java-1.8.0-openjdk    文件:SelectionVisible.java   
@Override
public void init() {
    tf = new TextField(20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                     + "The text 012345 should be selected in the TextField.\n"
                                     + "If this is what you observe, then the test passes.\n"
                                     + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
项目:lookaside_java-1.8.0-openjdk    文件:DeadKeySystemAssertionDialog.java   
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
项目:javify    文件:GtkTextFieldPeer.java   
void create ()
{
  Font f = awtComponent.getFont ();

  // By default, Sun sets a TextField's font when its peer is
  // created.  If f != null then the peer's font is set by
  // GtkComponent.create.
  if (f == null)
    {
      f = new Font ("Dialog", Font.PLAIN, 12);
      awtComponent.setFont (f);
    }

  FontMetrics fm = getFontMetrics (f);

  TextField tf = ((TextField) awtComponent);
  int cols = tf.getColumns ();

  int text_width = cols * fm.getMaxAdvance ();

  create (text_width);

  setEditable (tf.isEditable ());
}
项目:code-similarity    文件:TiledImageComponent.java   
/** Set things up nicely. */
public TiledImageComponent() {

    setLayout(new FlowLayout());
    add(new Label("Name:", Label.CENTER));
    add(nameTF=new TextField(10));

    add(new Label("Password:", Label.CENTER));
    add(passTF=new TextField(10));
    passTF.setEchoChar('*');

    add(new Label("Domain:", Label.CENTER));
    add(domainTF=new TextField(10));

    im = getToolkit().getImage(DEFAULT_IMAGE_NAME);
}
项目:jvm-stm    文件:GtkTextFieldPeer.java   
void create ()
{
  Font f = awtComponent.getFont ();

  // By default, Sun sets a TextField's font when its peer is
  // created.  If f != null then the peer's font is set by
  // GtkComponent.create.
  if (f == null)
    {
      f = new Font ("Dialog", Font.PLAIN, 12);
      awtComponent.setFont (f);
    }

  FontMetrics fm = getFontMetrics (f);

  TextField tf = ((TextField) awtComponent);
  int cols = tf.getColumns ();

  int text_width = cols * fm.getMaxAdvance ();

  create (text_width);

  setEditable (tf.isEditable ());
}
项目:OpenNFMM    文件:StageMaker.java   
private void fixtext(final TextField textfield) {
    String string = textfield.getText();
    string = string.replace('\"', '#');
    final String string330 = "\\";
    String string331 = "";
    int i = 0;
    int i332 = -1;
    rd.setFont(new Font("Arial", 1, 12));
    ftm = rd.getFontMetrics();
    for (/**/; i < string.length(); i++) {
        final String string333 = "" + string.charAt(i);
        if (string333.equals("|") || string333.equals(",") || string333.equals("(") || string333.equals(")") || string333.equals("#") || string333.equals(string330) || string333.equals("!") || string333.equals("?") || string333.equals("~") || string333.equals(".") || string333.equals("@") || string333.equals("$") || string333.equals("%") || string333.equals("^") || string333.equals("&") || string333.equals("*") || string333.equals("+") || string333.equals("=") || string333.equals(">") || string333.equals("<") || string333.equals("/") || string333.equals(";") || string333.equals(":") || ftm.stringWidth(string331) > 274) {
            i332 = i;
        } else {
            string331 = "" + string331 + string333;
        }
    }
    if (i332 != -1) {
        textfield.setText(string331);
        textfield.select(i332, i332);
    }
}
项目:OpenNFMM    文件:Login.java   
private void fixtext(final TextField textfield) {
    String string = textfield.getText();
    string = string.replace('\"', '#');
    final String string64 = "\\";
    String string65 = "";
    int i = 0;
    int i66 = -1;
    for (/**/ ; i < string.length(); i++) {
        final String string67 = "" + string.charAt(i);
        if (string67.equals("|") || string67.equals(",") || string67.equals("(") || string67.equals(")") || string67.equals("#") || string67.equals(string64) || string67.equals("!") || string67.equals("?") || string67.equals(" ") || string67.equals("~") || string67.equals("$") || string67.equals("%") || string67.equals("^") || string67.equals("&") || string67.equals("*") || string67.equals("+") || string67.equals("=") || string67.equals(">") || string67.equals("<") || string67.equals("/") || string67.equals("'") || string67.equals(";") || string67.equals(":") || string67.equals("\u00a0")) {
            i66 = i;
        } else {
            string65 = "" + string65 + string67;
        }
    }
    if (i66 != -1) {
        textfield.setText(string65);
        textfield.select(i66, i66);
    }
}
项目:OpenNFMM    文件:CarMaker.java   
private void fixtext(final TextField textfield) {
    String string = textfield.getText();
    string = string.replace('\"', '#');
    final String string360 = "\\";
    String string361 = "";
    int i = 0;
    int i362 = -1;
    for (/**/; i < string.length(); i++) {
        final String string363 = "" + string.charAt(i);
        if (string363.equals("|") || string363.equals(",") || string363.equals("(") || string363.equals(")") || string363.equals("#") || string363.equals(string360) || string363.equals("!") || string363.equals("?") || string363.equals("~") || string363.equals(".") || string363.equals("@") || string363.equals("$") || string363.equals("%") || string363.equals("^") || string363.equals("&") || string363.equals("*") || string363.equals("+") || string363.equals("=") || string363.equals(">") || string363.equals("<") || string363.equals("/") || string363.equals("'") || string363.equals(";") || string363.equals(":") || i > 15) {
            i362 = i;
        } else {
            string361 = "" + string361 + string363;
        }
    }
    if (i362 != -1) {
        textfield.setText(string361);
        textfield.select(i362, i362);
    }
}
项目:LuceneDB    文件:UserDefineDocumentCreatorTest.java   
@Test
public void simpleTest() throws IOException {
    LuceneValuesDB valuesDB = new LuceneValuesDB();
    URL testPath = LuceneValuesDB.class.getResource("test.csv");

    @SuppressWarnings("unchecked")
    UserDefineDocumentCreator creator = new UserDefineDocumentCreator(new Class[] {
            IntField.class,
            StringField.class,
            FloatField.class,
            TextField.class
    }, new String[] {
            "docNum",
            "docType",
            "score",
            "text"
    });

    valuesDB.open(new File(testPath.getFile()), new CSVParser(), creator);

    assertEquals(1, valuesDB.search("docNum", 0).length);
    assertEquals(1, valuesDB.search("docType", "a").length);
    assertEquals(2, valuesDB.search("score", "0.1").length);
    assertEquals(1, valuesDB.search("text", "this is a pen").length);
}
项目:infobip-open-jdk-8    文件:SelectionVisible.java   
@Override
public void init() {
    tf = new TextField(20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                     + "The text 012345 should be selected in the TextField.\n"
                                     + "If this is what you observe, then the test passes.\n"
                                     + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
项目:infobip-open-jdk-8    文件:DeadKeySystemAssertionDialog.java   
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
项目:jdk8u-dev-jdk    文件:SelectionVisible.java   
@Override
public void init() {
    tf = new TextField(20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                     + "The text 012345 should be selected in the TextField.\n"
                                     + "If this is what you observe, then the test passes.\n"
                                     + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
项目:jdk8u-dev-jdk    文件:MultiResolutionSplashTest.java   
static void testFocus() throws Exception {

        System.out.println("Focus Test!");
        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();

        if(!textField.getText().equals("ab")){
            throw new RuntimeException("Focus is lost!");
        }
    }
项目:jdk8u-dev-jdk    文件:DeadKeySystemAssertionDialog.java   
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
项目:ij-ridgedetection    文件:GenericDialogPlus.java   
/**
 * Adds the directory or file field.
 *
 * @param label
 *            the label
 * @param defaultPath
 *            the default path
 * @param columns
 *            the columns
 */
public void addDirectoryOrFileField(String label, String defaultPath, int columns) {
    addStringField(label, defaultPath, columns);
    if (isHeadless())
        return;

    TextField text = (TextField) stringField.lastElement();
    GridBagLayout layout = (GridBagLayout) getLayout();
    GridBagConstraints constraints = layout.getConstraints(text);

    Button button = new Button("Browse...");
    DirectoryListener listener = new DirectoryListener("Browse for " + label, text,
            JFileChooser.FILES_AND_DIRECTORIES);
    button.addActionListener(listener);
    button.addKeyListener(this);

    Panel panel = new Panel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    panel.add(text);
    panel.add(button);

    layout.setConstraints(panel, constraints);
    add(panel);
}
项目:ij-ridgedetection    文件:GenericDialogPlus.java   
/**
 * Adds the directory field.
 *
 * @param label
 *            the label
 * @param defaultPath
 *            the default path
 * @param columns
 *            the columns
 */
public void addDirectoryField(String label, String defaultPath, int columns) {
    addStringField(label, defaultPath, columns);
    if (isHeadless())
        return;

    TextField text = (TextField) stringField.lastElement();
    GridBagLayout layout = (GridBagLayout) getLayout();
    GridBagConstraints constraints = layout.getConstraints(text);

    Button button = new Button("Browse...");
    DirectoryListener listener = new DirectoryListener("Browse for " + label, text);
    button.addActionListener(listener);
    button.addKeyListener(this);

    Panel panel = new Panel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    panel.add(text);
    panel.add(button);

    layout.setConstraints(panel, constraints);
    add(panel);
}
项目:ij-ridgedetection    文件:GenericDialogPlus.java   
/**
 * Adds the file field.
 *
 * @param label
 *            the label
 * @param defaultPath
 *            the default path
 * @param columns
 *            the columns
 */
public void addFileField(String label, String defaultPath, int columns) {
    addStringField(label, defaultPath, columns);
    if (isHeadless())
        return;

    TextField text = (TextField) stringField.lastElement();
    GridBagLayout layout = (GridBagLayout) getLayout();
    GridBagConstraints constraints = layout.getConstraints(text);

    Button button = new Button("Browse...");
    FileListener listener = new FileListener("Browse for " + label, text);
    button.addActionListener(listener);
    button.addKeyListener(this);

    Panel panel = new Panel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    panel.add(text);
    panel.add(button);

    layout.setConstraints(panel, constraints);
    add(panel);
}
项目:wwwa    文件:AWTExample.java   
public static void main(String[] args) {

    Container container = new Container();
    Panel panel = new Panel();
    Menu menu = new Menu();             //!!! its not component
    TextField textField = new TextField();
    container.add(textField);

    Window win = new Window(null);
    win.pack();


    menu.setShortcut(new MenuShortcut(12));
    new MenuItem("label", new MenuShortcut(33, true));

    Menu file = new Menu("File"); 
    MenuItem print; 
    file.add(print = new MenuItem("Print", new MenuShortcut('p'))); 

}
项目:3D_Viewer    文件:SaveSession.java   
static String showPathDialog(final String title, final String msg) {
    final GenericDialog gd = new GenericDialog(title);
    gd.addMessage(msg);
    final Panel p = new Panel(new FlowLayout());
    final TextField tf = new TextField(30);
    p.add(tf);
    final Button b = new Button("...");
    p.add(b);
    b.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            final SaveDialog sd = new SaveDialog("Select path", "untitled", ".obj");
            final String dir = sd.getDirectory();
            final String file = sd.getFileName();
            final File f = new File(dir, file);
            tf.setText(f.getAbsolutePath());
        }
    });
    gd.addPanel(p);
    gd.showDialog();
    if (gd.wasCanceled()) return null;
    return new File(tf.getText()).getAbsolutePath();
}
项目:3D_Viewer    文件:InteractiveTransformDialog.java   
private void addTextListener(final TextField tf) {
    tf.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(final KeyEvent arg0) {
            try {
                final Matrix4f m = fromFields();
                matrixTA.setText(InteractiveTransformDialog.this.toString(m));
                transformationUpdated(m);
            }
            catch (final Exception e) {
                System.out.println(e.getMessage());
            }
        }
    });
}
项目:3D_Viewer    文件:PrimitiveDialogs.java   
public BoxDialog(final Image3DUniverse univ) {
    super("Box", univ);
    addStringField("Name", "");
    addStringField("Lower corner", "");
    addStringField("Upper corner", "");
    @SuppressWarnings("rawtypes")
    final Vector v = getStringFields();
    tf0 = (TextField) v.get(0);
    tf1 = (TextField) v.get(1);
    tf2 = (TextField) v.get(2);
    tf0.addFocusListener(this);
    tf1.addFocusListener(this);
    tf2.addFocusListener(this);
    showDialog();
    if (wasCanceled()) univ.removeContent(tf0.getText());
    else{
        updatePreview();
        Executer.record( Executer.ADD_BOX, tf0.getText(), 
                tf1.getText(), tf2.getText());
    }
}
项目:3D_Viewer    文件:PrimitiveDialogs.java   
public SphereDialog(final Image3DUniverse univ) {
    super("Sphere", univ);
    addStringField("Name", "");
    addStringField("Center", "");
    addNumericField("Radius", 0, 4);
    @SuppressWarnings("rawtypes")
    Vector v = getStringFields();
    tf0 = (TextField) v.get(0);
    tf1 = (TextField) v.get(1);
    v = getNumericFields();
    tf2 = (TextField) v.get(0);
    tf0.addFocusListener(this);
    tf1.addFocusListener(this);
    tf2.addFocusListener(this);
    showDialog();
    if (wasCanceled()) univ.removeContent(tf0.getText());
    else{ 
        updatePreview();
        Executer.record( Executer.ADD_SPHERE, tf0.getText(), 
                tf1.getText(), tf2.getText());
    }
}