Java Code Examples for java.awt.TextField

The following are top voted examples for showing how to use java.awt.TextField. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: youyoulearning   File: TFActionEvent.java   Source Code and License 11 votes vote down vote up
public TFFrame() {
	TextField tf = new TextField();
	add(tf);
	tf.addActionListener(new TFActionListener());
	tf.setEchoChar('*');
	pack();
	setVisible(true);
}
 
Example 2
Project: jdk8u-jdk   File: SelectionVisible.java   Source Code and License 8 votes vote down vote up
@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);
}
 
Example 3
Project: openjdk-jdk10   File: OverScrollTest.java   Source Code and License 7 votes vote down vote up
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();
}
 
Example 4
Project: Servlet_Applet_Communication   File: LoginApplet.java   Source Code and License 6 votes vote down vote up
@Override
public void init() {
this.setVisible(true);
this.setSize(500, 500);
this.setBackground(Color.green);
this.setLayout(new FlowLayout());

l1 = new Label("User Name");
l2 = new Label("Password");
tf1 = new TextField(20);
tf2 = new TextField(20);
tf2.setEchoChar('*');
b = new Button("Login");
b.addActionListener(this);

Font font = new Font("arial", Font.BOLD, 25);
l1.setFont(font);
l2.setFont(font);
tf1.setFont(font);
tf2.setFont(font);
b.setFont(font);

this.add(l1);
this.add(tf1);
this.add(l2);
this.add(tf2);
this.add(b);

}
 
Example 5
Project: dev-courses   File: ConnectionDialog.java   Source Code and License 6 votes vote down vote up
public void actionPerformed(ActionEvent ev) {

        String s = ev.getActionCommand();

        if (s.equals("ConnectOk") || (ev.getSource() instanceof TextField)) {
            try {
                if (mURL.getText().indexOf('\u00AB') >= 0) {
                    throw new Exception("please specify db path");
                }

                mConnection = createConnection(mDriver.getText(),
                                               mURL.getText(),
                                               mUser.getText(),
                                               mPassword.getText());

                if (mName.getText() != null
                        && mName.getText().trim().length() != 0) {
                    ConnectionSetting newSetting =
                        new ConnectionSetting(mName.getText(),
                                              mDriver.getText(),
                                              mURL.getText(), mUser.getText(),
                                              mPassword.getText());

                    ConnectionDialogCommon.addToRecentConnectionSettings(
                        settings, newSetting);
                }

                dispose();
            } catch (java.io.IOException ioe) {
                dispose();
            } catch (Exception e) {
                e.printStackTrace();
                mError.setText(e.toString());
            }
        } else if (s.equals("ConnectCancel")) {
            dispose();
        }
    }
 
Example 6
Project: jdk8u-jdk   File: DeadKeySystemAssertionDialog.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 7
Project: openjdk-jdk10   File: DisabledUndoTest.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 8
Project: openjdk-jdk10   File: SelectionVisible.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 9
Project: openjdk-jdk10   File: MultiResolutionSplashTest.java   Source Code and License 6 votes vote down vote up
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!");
        }
    }
 
Example 10
Project: openjdk-jdk10   File: UnixMultiResolutionSplashTest.java   Source Code and License 6 votes vote down vote up
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!");
        }
    }
 
Example 11
Project: openjdk-jdk10   File: DeadKeySystemAssertionDialog.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 12
Project: openjdk9   File: OverScrollTest.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 13
Project: openjdk9   File: SelectionVisible.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 14
Project: openjdk9   File: UnixMultiResolutionSplashTest.java   Source Code and License 6 votes vote down vote up
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!");
        }
    }
 
Example 15
Project: openjdk9   File: DeadKeySystemAssertionDialog.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 16
Project: OpenNFMM   File: StageMaker.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 17
Project: OpenNFMM   File: Login.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 18
Project: OpenNFMM   File: CarMaker.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 19
Project: jdk8u_jdk   File: SelectionVisible.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 20
Project: jdk8u_jdk   File: DeadKeySystemAssertionDialog.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 21
Project: lookaside_java-1.8.0-openjdk   File: SelectionVisible.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 22
Project: lookaside_java-1.8.0-openjdk   File: DeadKeySystemAssertionDialog.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 23
Project: javify   File: GtkTextFieldPeer.java   Source Code and License 6 votes vote down vote up
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 ());
}
 
Example 24
Project: code-similarity   File: TiledImageComponent.java   Source Code and License 6 votes vote down vote up
/** 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);
}
 
Example 25
Project: jvm-stm   File: GtkTextFieldPeer.java   Source Code and License 6 votes vote down vote up
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 ());
}
 
Example 26
Project: OpenNFMM   File: StageMaker.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 27
Project: OpenNFMM   File: Login.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 28
Project: OpenNFMM   File: CarMaker.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 29
Project: LuceneDB   File: UserDefineDocumentCreatorTest.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 30
Project: infobip-open-jdk-8   File: SelectionVisible.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 31
Project: infobip-open-jdk-8   File: DeadKeySystemAssertionDialog.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 32
Project: jdk8u-dev-jdk   File: SelectionVisible.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 33
Project: jdk8u-dev-jdk   File: MultiResolutionSplashTest.java   Source Code and License 6 votes vote down vote up
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!");
        }
    }
 
Example 34
Project: jdk8u-dev-jdk   File: DeadKeySystemAssertionDialog.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 35
Project: ij-ridgedetection   File: GenericDialogPlus.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 36
Project: ij-ridgedetection   File: GenericDialogPlus.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 37
Project: ij-ridgedetection   File: GenericDialogPlus.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 38
Project: wwwa   File: AWTExample.java   Source Code and License 6 votes vote down vote up
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'))); 

}
 
Example 39
Project: 3D_Viewer   File: SaveSession.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 40
Project: 3D_Viewer   File: InteractiveTransformDialog.java   Source Code and License 6 votes vote down vote up
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());
			}
		}
	});
}
 
Example 41
Project: 3D_Viewer   File: PrimitiveDialogs.java   Source Code and License 6 votes vote down vote up
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());
	}
}
 
Example 42
Project: 3D_Viewer   File: PrimitiveDialogs.java   Source Code and License 6 votes vote down vote up
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());
	}
}
 
Example 43
Project: 3D_Viewer   File: PrimitiveDialogs.java   Source Code and License 6 votes vote down vote up
public ConeDialog(final Image3DUniverse univ) {
	super("Cone", univ);
	addStringField("Name", "");
	addStringField("From", "");
	addStringField("To", "");
	addNumericField("Radius", 0, 4);
	@SuppressWarnings("rawtypes")
	Vector v = getStringFields();
	tf0 = (TextField) v.get(0);
	tf1 = (TextField) v.get(1);
	tf2 = (TextField) v.get(2);
	v = getNumericFields();
	tf3 = (TextField) v.get(0);
	tf0.addFocusListener(this);
	tf1.addFocusListener(this);
	tf2.addFocusListener(this);
	tf3.addFocusListener(this);
	showDialog();
	if (wasCanceled()) univ.removeContent(tf0.getText());
	else{
		updatePreview();
		Executer.record( Executer.ADD_CONE, tf0.getText(), 
				tf1.getText(), tf2.getText(), tf3.getText() );
	}
}
 
Example 44
Project: OLD-OpenJDK8   File: SelectionVisible.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 45
Project: OLD-OpenJDK8   File: DeadKeySystemAssertionDialog.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 46
Project: JamVM-PH   File: GtkTextFieldPeer.java   Source Code and License 6 votes vote down vote up
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 ());
}
 
Example 47
Project: bigdataviewer_fiji   File: ExportCellVoyagerPlugIn.java   Source Code and License 6 votes vote down vote up
public static void addBrowseToCellVoyagerFolder( final GenericDialogPlus dialog, final String label, final String defaultPath, final int columns )
{
	dialog.addStringField( label, defaultPath, columns );

	final TextField text = ( TextField ) dialog.getStringFields().lastElement();
	final GridBagLayout layout = ( GridBagLayout ) dialog.getLayout();
	final GridBagConstraints constraints = layout.getConstraints( text );

	final Button button = new Button( "Browse..." );
	final ChooseCellVoyagerDirListener listener = new ChooseCellVoyagerDirListener( text );
	button.addActionListener( listener );
	button.addKeyListener( dialog );

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

	layout.setConstraints( panel, constraints );
	dialog.add( panel );
}
 
Example 48
Project: bigdataviewer_fiji   File: PluginHelper.java   Source Code and License 6 votes vote down vote up
public static void addSaveAsFileField( final GenericDialogPlus dialog, final String label, final String defaultPath, final int columns) {
	dialog.addStringField( label, defaultPath, columns );

	final TextField text = ( TextField ) dialog.getStringFields().lastElement();
	final GridBagLayout layout = ( GridBagLayout ) dialog.getLayout();
	final GridBagConstraints constraints = layout.getConstraints( text );

	final Button button = new Button( "Browse..." );
	final ChooseXmlFileListener listener = new ChooseXmlFileListener( text );
	button.addActionListener( listener );
	button.addKeyListener( dialog );

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

	layout.setConstraints( panel, constraints );
	dialog.add( panel );
}
 
Example 49
Project: MusicGenerator   File: MIDIKeyboardStreamer.java   Source Code and License 6 votes vote down vote up
@Override
public void init() {
    
    Button button = new Button("Clear");
    button.addActionListener(this);

    typingArea = new TextField(20);
    typingArea.addKeyListener(this);

    displayArea = new TextArea(5, 20);
    displayArea.setEditable(false);

    setLayout(new BorderLayout());
    add("Center", displayArea);
    add("North", typingArea);
    add("South", button);
    
    try {
        tsocket = new DatagramSocket(DEFAULT_TRANSMITTER_PORT);
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    initialize();
}
 
Example 50
Project: pos-tagger   File: Viterbi.java   Source Code and License 6 votes vote down vote up
@Override
public void init() {
	this.canvas = new HMMCanvas();

	this.setLayout(new BorderLayout());
	this.p = new Panel();
	this.sentence = new TextField("moo hello quack", 20);
	this.bstart = new Button("  Start  ");
	this.bskip = new Button("Auto");
	this.bstart.addActionListener(this);
	this.bskip.addActionListener(this);
	this.p.add(this.sentence);
	this.p.add(this.bstart);
	this.p.add(this.bskip);
	this.hmmdesc = new TextArea(initialHMM, 4, 20);
	this.add("North", this.canvas);
	this.add("Center", this.p);
	this.add("South", this.hmmdesc);

}
 
Example 51
Project: youyoulearning   File: TFMath.java   Source Code and License 6 votes vote down vote up
public void launchFrame() {
	num1 = new TextField(10);
	num2 = new TextField(10);
	num3 = new TextField(15);
	Label lblPlus = new Label("+");
	Button btnEqual = new Button("=");
	btnEqual.addActionListener(new ActionListener() {

		public void actionPerformed(ActionEvent e) {
			int n1 = Integer.parseInt(num1.getText());
			int n2 = Integer.parseInt(num2.getText());
			num3.setText((n1 + n2) + "");
		}
	});
	setLayout(new FlowLayout());
	add(num1);
	add(lblPlus);
	add(num2);
	add(btnEqual);
	add(num3);
	pack();
	setVisible(true);
}
 
Example 52
Project: SPIM_Registration   File: PluginHelper.java   Source Code and License 6 votes vote down vote up
public static void addSaveAsFileField( final GenericDialogPlus dialog, final String label, final String defaultPath, final int columns) {
	dialog.addStringField( label, defaultPath, columns );

	final TextField text = ( TextField ) dialog.getStringFields().lastElement();
	final GridBagLayout layout = ( GridBagLayout ) dialog.getLayout();
	final GridBagConstraints constraints = layout.getConstraints( text );

	final Button button = new Button( "Browse..." );
	final ChooseXmlFileListener listener = new ChooseXmlFileListener( text );
	button.addActionListener( listener );
	button.addKeyListener( dialog );

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

	layout.setConstraints( panel, constraints );
	dialog.add( panel );
}
 
Example 53
Project: SPIM_Registration   File: GenericLoadParseQueryXML.java   Source Code and License 6 votes vote down vote up
protected void addListeners( final GenericDialog gd, final TextField tf, final Label label1, final Label label2  )
{
	final GenericLoadParseQueryXML< ?,?,?,?,?,? > lpq = this;
	
	// using TextListener instead
	tf.addTextListener( new TextListener()
	{	
		@Override
		public void textValueChanged( final TextEvent t )
		{
			if ( t.getID() == TextEvent.TEXT_VALUE_CHANGED )
			{
				final String xmlFilename = tf.getText();
				
				// try parsing if it ends with XML
				tryParsing( xmlFilename, false );
				
				label1.setText( lpq.message1 );
				label2.setText( lpq.message2 );
				label1.setForeground( lpq.color );
				label2.setForeground( lpq.color );
			}
		}
	});
}
 
Example 54
Project: GDSC   File: FileMatchCalculator.java   Source Code and License 6 votes vote down vote up
public void mouseClicked(MouseEvent e)
{
	if (e.getClickCount() > 1) // Double-click
	{
		TextField text;
		String title;
		if (e.getSource() == text1)
		{
			text = text1;
			title = "Coordinate_file_1";
		}
		else
		{
			text = text2;
			title = "Coordinate_file_2";
		}
		String[] path = decodePath(text.getText());
		OpenDialog chooser = new OpenDialog(title, path[0], path[1]);
		if (chooser.getFileName() != null)
		{
			text.setText(chooser.getDirectory() + chooser.getFileName());
		}
	}
}
 
Example 55
Project: GDSC   File: FindFoci.java   Source Code and License 6 votes vote down vote up
public void mouseClicked(MouseEvent e)
{
	if (e.getClickCount() > 1 && e.getSource() instanceof TextField) // Double-click
	{
		TextField tf = (TextField) e.getSource();
		String path = tf.getText();
		boolean recording = Recorder.record;
		Recorder.record = false;
		if (tf == textParamFile)
		{
			path = Utils.getFilename("Choose_a_parameter_file", path);
		}
		else
		{
			path = Utils.getDirectory("Choose_a_directory", path);
		}
		Recorder.record = recording;
		if (path != null)
			tf.setText(path);
	}
}
 
Example 56
Project: EFTEMj   File: GenericDialogPlus.java   Source Code and License 6 votes vote down vote up
public void addDirectoryOrFileField(final String label,
	final String defaultPath, final int columns)
{
	addStringField(label, defaultPath, columns);
	if (isHeadless()) return;

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

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

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

	layout.setConstraints(panel, constraints);
	add(panel);
}
 
Example 57
Project: EFTEMj   File: GenericDialogPlus.java   Source Code and License 6 votes vote down vote up
public void addDirectoryField(final String label, final String defaultPath,
	final int columns)
{
	addStringField(label, defaultPath, columns);
	if (isHeadless()) return;

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

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

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

	layout.setConstraints(panel, constraints);
	add(panel);
}
 
Example 58
Project: EFTEMj   File: GenericDialogPlus.java   Source Code and License 6 votes vote down vote up
public void addFileField(final String label, final String defaultPath,
	final int columns)
{
	addStringField(label, defaultPath, columns);
	if (isHeadless()) return;

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

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

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

	layout.setConstraints(panel, constraints);
	add(panel);
}
 
Example 59
Project: classpath   File: GtkTextFieldPeer.java   Source Code and License 6 votes vote down vote up
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 ());
}
 
Example 60
Project: pdfxtk   File: StringRequester.java   Source Code and License 6 votes vote down vote up
public StringRequester(Frame parent, String title,
  String lines, String posText_, String negText) {
  
  super(parent, title, true);
  setLayout(new GridBagLayout());
  posText = posText_;
  
  add(new MultiLineLabel(lines), Awt.constraints(true));
  
  text = new TextField(30);
  add(text, Awt.constraints(true, 10, 4, GridBagConstraints.HORIZONTAL));
  
  Button pos = new Button(posText);
  add(pos, Awt.constraints(false, 10, 4, GridBagConstraints.HORIZONTAL));
  pos.addActionListener(this);
  
  Button neg = new Button(negText);
  add(neg, Awt.constraints(true, 10, 4, GridBagConstraints.HORIZONTAL));
  neg.addActionListener(this);
  
  pack();
}