Java Code Examples for javax.swing.JTextField#requestFocusInWindow()

The following examples show how to use javax.swing.JTextField#requestFocusInWindow() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public boolean validateUrl(JTextField field) {
    String urlStr = field.getText();
    if (urlStr.isEmpty()) {
        showWarningDialog(Constant.messages.getString(MESSAGE_PREFIX + "url.empty"));
        field.requestFocusInWindow();
        return false;
    } else if ("http://".equals(urlStr) || "https://".equals(urlStr)) {
        showWarningDialog(
                Constant.messages.getString(MESSAGE_PREFIX + "url.invalid", urlStr, ""));
        field.requestFocusInWindow();
        return false;
    }
    try {
        new URL(urlStr);
        new URI(urlStr, true);
    } catch (Exception e) {
        showWarningDialog(
                Constant.messages.getString(
                        MESSAGE_PREFIX + "url.invalid", urlStr, e.getMessage()));
        field.requestFocusInWindow();
        return false;
    }
    return true;
}
 
Example 2
Source Project: FlatLaf   File: FlatSpinnerUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void focusGained( FocusEvent e ) {
	spinner.repaint();

	// if spinner gained focus, transfer it to the editor text field
	if( e.getComponent() == spinner ) {
		JTextField textField = getEditorTextField( spinner.getEditor() );
		if( textField != null )
			textField.requestFocusInWindow();
	}
}
 
Example 3
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 4
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 5
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 6
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 7
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 8
static void createAndShowGUI(Robot robot) {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    robot.waitForIdle();

    textField.requestFocusInWindow();
    robot.waitForIdle();

}
 
Example 9
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 10
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 11
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 12
private static void insertFile(JTextField textField, File file) {
        String path = file.getAbsolutePath();
        if (path.contains(" ")) path = "\"" + path + "\"";                      // NOI18N
        
//        try { textField.getDocument().insertString(textField.getCaretPosition(), path, null); }
        try {
            textField.getDocument().insertString(0, path, null);
            textField.select(0, path.length());
            textField.requestFocusInWindow();
        } catch (BadLocationException ex) {}
    }
 
Example 13
public void mouseReleased(MouseEvent e) {
	if (e.isPopupTrigger() && e.getSource() instanceof JTextField) {
		JTextField textfield = (JTextField) e.getSource();
		if (Boolean.TRUE.equals(textfield
				.getClientProperty("DisablePopupMenu"))) {
			return;
		}
		textfield.requestFocusInWindow();
		show(textfield, e.getX(), e.getY());
	}
}
 
Example 14
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 15
private void startEditingNextRow(final JTable statsTable, final int col, final int nextRow, JTextField textField)
{
	if (nextRow >= 0 && nextRow < getRowCount() && col >= 0 && col < getColumnCount())
	{
		statsTable.editCellAt(nextRow, col);
		textField.requestFocusInWindow();
	}
}
 
Example 16
private void startEditingNextRow(final JTable statsTable, final int col, final int nextRow, JTextField textField)
{
	if (nextRow >= 0 && nextRow < getRowCount() && col >= 0 && col < getColumnCount())
	{
		statsTable.editCellAt(nextRow, col);
		textField.requestFocusInWindow();
	}
}
 
Example 17
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 18
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
Example 19
Source Project: ios-image-util   File: SplitterFrame.java    License: MIT License 5 votes vote down vote up
/**
 * Set size as text to text field.
 *
 * @param text
 * @param value
 */
private void setSizeText(JTextField text, String value) {
	try {
		setImageSize(text, value);
	} catch (Throwable t) {
		t.printStackTrace();
		text.requestFocusInWindow();
	}
}
 
Example 20
public void mouseReleased(MouseEvent e) {
	if (e.isPopupTrigger() && e.getSource() instanceof JTextField) {
		JTextField textfield = (JTextField) e.getSource();
		if (Boolean.TRUE.equals(textfield
				.getClientProperty("DisablePopupMenu"))) {
			return;
		}
		textfield.requestFocusInWindow();
		show(textfield, e.getX(), e.getY());
	}
}