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

The following examples show how to use javax.swing.JTextField#addKeyListener() . 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
Source Project: gcs   File: Search.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Creates the search panel.
 *
 * @param target The search target.
 */
public Search(SearchTarget target) {
    mTarget = target;

    mFilterField = new JTextField(10);
    mFilterField.getDocument().addDocumentListener(this);
    mFilterField.addKeyListener(this);
    mFilterField.addFocusListener(this);
    mFilterField.setToolTipText(Text.wrapPlainTextForToolTip(I18n.Text("Enter text here and press RETURN to select all matching items")));
    // This client property is specific to Mac OS X
    mFilterField.putClientProperty("JTextField.variant", "search");
    mFilterField.setMinimumSize(new Dimension(60, mFilterField.getPreferredSize().height));
    add(mFilterField);

    mHits = new JLabel();
    mHits.setToolTipText(Text.wrapPlainTextForToolTip(I18n.Text("The number of matches found")));
    adjustHits();
    add(mHits);

    FlexRow row = new FlexRow();
    row.add(mFilterField);
    row.add(mHits);
    row.apply(this);
}
 
Example 2
Source Project: netbeans   File: FileCompletionPopup.java    License: Apache License 2.0 6 votes vote down vote up
public FileCompletionPopup(JFileChooser chooser, JTextField textField, Vector<File> files) {
    this.list = new JList(files);
    this.textField = textField;
    this.chooser = chooser;
    list.setVisibleRowCount(4);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    
    JScrollPane jsp = new JScrollPane(list);
    add(jsp);
    
    list.setFocusable(false);
    jsp.setFocusable(false);
    setFocusable(false);
    
    list.addFocusListener(new FocusHandler());
    list.addMouseListener(new MouseHandler());
    list.addMouseMotionListener(new MouseHandler());
    
    textField.addKeyListener(this);
}
 
Example 3
public PanJigTags(){
  
  setBackground(UI.BUTTON_PURPLE);
  setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  
  Component horizontalStrut = Box.createHorizontalStrut(4);
  add(horizontalStrut);
  
  JLabel lbljigtag = new JLabel("Jig Tags =");
  add(lbljigtag);
  lbljigtag.setFont(new Font("Dialog", Font.BOLD, 14));
  
  Component horizontalStrut_3 = Box.createHorizontalStrut(4);
  add(horizontalStrut_3);
  
  txtjigtag = new JTextField("foo",20);
  txtjigtag.setBackground(UI.BUTTON_YELLOW);
  add(txtjigtag);
  txtjigtag.setFont(new Font("DejaVu Sans Mono", Font.PLAIN, 18));
  txtjigtag.setBorder(null);
  txtjigtag.addKeyListener(new KeyAdapter(){
    public void keyReleased(KeyEvent e){
      GE.ge.editor_jig.setJigTags(txtjigtag.getText());}});
  
  Component horizontalStrut_1 = Box.createHorizontalStrut(4);
  add(horizontalStrut_1);
  
}
 
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
protected void createDesign() {
    setLayout(new GridLayout());
    nameComboBox = new JComboBox();
    valueTextField = new JTextField();
    add(nameComboBox);
    add(valueTextField);
    valueTextField.addKeyListener(this);
}
 
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
public static void autocomplete(JTextField txtSearch) {

		  final List<String> res = new ArrayList<>();
		  txtSearch.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				res.clear();
				if(!txtSearch.getText().isEmpty())
					res.addAll(MTGControler.getInstance().getEnabled(MTGCardsIndexer.class).suggestCardName(txtSearch.getText()));
				
			}
		});
		AutoCompleteDecorator.decorate(txtSearch,res,false);
		
	}
 
Example 9
@SuppressWarnings("unchecked")
private JPanel createInputPanel()
{
    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel innerPanel = new JPanel(new BorderLayout());
    m_comboBox = new JComboBox(getHistory().toArray());
    StringBuilder prototype = new StringBuilder(70);
    for (int i = 0; i < 40; ++i)
        prototype.append('-');
    m_comboBox.setPrototypeDisplayValue(prototype.toString());
    m_comboBox.setEditable(true);
    ComboBoxEditor editor = m_comboBox.getEditor();
    m_comboBox.addActionListener(this);
    m_textField = (JTextField)editor.getEditorComponent();
    m_textField.selectAll();
    KeyListener keyListener = new KeyAdapter()
        {
            public void keyPressed(KeyEvent e)
            {
                int c = e.getKeyCode();
                if (c == KeyEvent.VK_ESCAPE
                    && ! m_comboBox.isPopupVisible())
                    dispose();
            }
        };
    m_textField.addKeyListener(keyListener);
    GuiUtil.setMonospacedFont(m_comboBox);
    innerPanel.add(m_comboBox, BorderLayout.CENTER);
    outerPanel.add(innerPanel, BorderLayout.NORTH);
    return outerPanel;
}
 
Example 10
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 11
protected void createDesign() {
    setLayout(new GridLayout());
    nameComboBox = new JComboBox();
    valueTextField = new JTextField();
    add(nameComboBox);
    add(valueTextField);
    valueTextField.addKeyListener(this);
}
 
Example 12
private JPanel getTextInputField() {
	textInputArea = new JPanel();
	textInputArea.setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();

	commandLineText = new JTextField(0);
	//commandLineText.setPreferredSize(new Dimension(10, 10));
	commandLineSend = new JButton(Translator.get("Send"));
	//commandLineSend.setHorizontalAlignment(SwingConstants.EAST);
	c.gridwidth=4;
	c.weightx=1;
	c.fill=GridBagConstraints.HORIZONTAL;
	c.gridx=c.gridy=0;
	textInputArea.add(commandLineText,c);
	c.gridwidth=1;
	c.gridx=4;
	c.weightx=0;
	textInputArea.add(commandLineSend,c);

	commandLineText.addKeyListener(this);
	commandLineSend.addActionListener(this);

	//textInputArea.setMinimumSize(new Dimension(100,50));
	//textInputArea.setMaximumSize(new Dimension(10000,50));

	return textInputArea;
}
 
Example 13
public WhoIsControl() {
	super();
	setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
	// top panel, start/cancel button and JTextField
	_whoIsButton = new JButton(GO_IMG);
	_whoIsButton.setToolTipText(Resources.getLabel("whois.button"));
	_hostIpTextField = new JTextField(17);
	_hostIpTextField.setText(Resources.getLabel("enter.whois"));

	final FirstInputListener listener = new FirstInputListener(_hostIpTextField);
	_hostIpTextField.addMouseListener(listener);
	_hostIpTextField.addKeyListener(listener);
	_hostIpTextField.setToolTipText(Resources.getLabel("enter.whois"));

	add(_hostIpTextField);
	add(_whoIsButton);
	// search button enable if text is not blank
	_hostIpTextField.addKeyListener(new KeyAdapter() {
		@Override
		public void keyReleased(final KeyEvent e) {
			_whoIsButton.setEnabled(!_hostIpTextField.getText().equals(""));
			if (e.getKeyCode() == KeyEvent.VK_ENTER) {
				_whoIsButton.getActionListeners()[0].actionPerformed(new ActionEvent(this, 0, "whois"));
			}
		}
	});
	// action of search/cancel trace route
	_whoIsButton.addActionListener(arg0 -> whois());

	_whoIsButton.setEnabled(false);
	_autocomplete = new AutoCompleteComponent(_hostIpTextField, _services.getAutocomplete());
}
 
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
public AutoCompletionComboBoxEditor(ComboBoxEditor editor) {
	if ((editor.getEditorComponent() instanceof JTextField)) {
		this.editor = editor;
		editorComponent = (JTextField) editor.getEditorComponent();
		editorComponent.getDocument().addDocumentListener(docListener);
		editorComponent.addKeyListener(new KeyAdapter() {

			@Override
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
					setSelectedItem(editorComponent.getText());
					actionPerformed(new ActionEvent(this, 0, "editingStoped"));
					e.consume();
				} else if (e.getKeyCode() == KeyEvent.VK_TAB) {
					if (isPopupVisible()) {
						hidePopup();
					} else {
						showPopup();
					}
					e.consume();
				} else {
					super.keyPressed(e);
				}
			}
		});
	} else {
		throw new IllegalArgumentException("Only JTextField allowed as editor component");
	}
}
 
Example 16
protected void createDesign() {
    setLayout(new GridLayout());
    nameComboBox = new JComboBox();
    valueTextField = new JTextField();
    add(nameComboBox);
    add(valueTextField);
    valueTextField.addKeyListener(this);
}
 
Example 17
public RegexSearch()
{
    searchText = new JTextField("");
    searchText.addKeyListener(EnterKeyEvent.SINGLETON);
}
 
Example 18
Source Project: TrakEM2   File: Tree.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void createGUI() {
	this.frame = new JFrame("Nodes for " + Tree.this);
	frame.addWindowListener(new WindowAdapter() {
		@Override
		public void windowClosing(final WindowEvent we) {
			Tree.this.tndv = null;
		}
	});
	final JTabbedPane tabs = new JTabbedPane();
	tabs.setPreferredSize(new Dimension(500, 500));
	tabs.add("All nodes", new JScrollPane(table_allnodes));
	tabs.add("Branch nodes", new JScrollPane(table_branchnodes));
	tabs.add("End nodes", new JScrollPane(table_endnodes));

	final JTextField search = new JTextField(14);
	search.addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(final KeyEvent ke) {
			if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
				search(search.getText());
			}
		}
	});
	final JButton b = new JButton("Search");
	b.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(final ActionEvent ae) {
			search(search.getText());
		}
	});
	final JPanel pane = new JPanel();
	final GridBagLayout gb = new GridBagLayout();
	pane.setLayout(gb);
	final GridBagConstraints c = new GridBagConstraints();
	c.gridx = 0;
	c.gridy = 0;
	c.weightx = 1;
	c.gridwidth = 1;
	c.anchor = GridBagConstraints.NORTH;
	c.fill = GridBagConstraints.BOTH;
	c.insets = new Insets(4,10,5,2);
	gb.setConstraints(search, c);
	pane.add(search);
	c.gridx = 1;
	c.weightx = 0;
	c.fill = GridBagConstraints.NONE;
	c.insets = new Insets(4,0,5,10);
	gb.setConstraints(b, c);
	pane.add(b);
	c.gridx = 0;
	c.gridy = 1;
	c.gridwidth = 2;
	c.weighty = 1;
	c.fill = GridBagConstraints.BOTH;
	final JScrollPane scp = new JScrollPane(table_searchnodes);
	c.insets = new Insets(0,0,0,0);
	gb.setConstraints(scp, c);
	pane.add(scp);
	tabs.add("Search", pane);

	frame.getContentPane().add(tabs);
	frame.pack();
	ij.gui.GUI.center(frame);
	frame.setVisible(true);
}
 
Example 19
public Main_CustomersFrame() {

        this.setAutoscrolls(true);
        this.setMinimumSize(new Dimension(800, 600));
        /*make it default size of frame maximized */
        this.setMaximumSize(new Dimension(1000, 900));
        this.setBorder(new SoftBevelBorder(BevelBorder.RAISED, null, null, null, null));
        setLayout(new BorderLayout(0, 0));

        bean = LocaleBean.getInstance();
        loggingEngine = LoggingEngine.getInstance();
        componentOrientation = new ChangeComponentOrientation();
        componentOrientation.setThePanel(this);

        searchPanel.setDoubleBuffered(false);
        searchPanel.setAutoscrolls(true);
        add(searchPanel, BorderLayout.NORTH);
        searchPanel.setPreferredSize(new Dimension(10, 30));

        lblTableFilter = new JLabel("Type to search : ");
        lblTableFilter.setForeground(new Color(178, 34, 34));
        lblTableFilter.setSize(new Dimension(130, 25));
        lblTableFilter.setPreferredSize(new Dimension(130, 22));
        lblTableFilter.setHorizontalTextPosition(SwingConstants.CENTER);
        lblTableFilter.setAutoscrolls(true);
        lblTableFilter.setHorizontalAlignment(SwingConstants.LEFT);
        lblTableFilter.setFont(new Font("Dialog", Font.BOLD, 15));

        searchFilterField = new JTextField();
        searchFilterField.setDragEnabled(true);
        searchFilterField.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, new Color(0, 191, 255), null, null, null));
        searchFilterField.setPreferredSize(new Dimension(200, 22));
        searchFilterField.setIgnoreRepaint(true);
        searchFilterField.setColumns(10);
        searchFilterField.setFont(new Font("Dialog", Font.BOLD, 13));
        searchFilterField.setHorizontalAlignment(SwingConstants.LEFT);
        GroupLayout gl_searchPanel = new GroupLayout(searchPanel);
        gl_searchPanel.setHorizontalGroup(
                gl_searchPanel.createParallelGroup(Alignment.LEADING)
                        .addGroup(gl_searchPanel.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(lblTableFilter, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(ComponentPlacement.RELATED)
                                .addComponent(searchFilterField, GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                                .addGap(118))
        );
        gl_searchPanel.setVerticalGroup(
                gl_searchPanel.createParallelGroup(Alignment.LEADING)
                        .addGroup(gl_searchPanel.createSequentialGroup()
                                .addGap(5)
                                .addGroup(gl_searchPanel.createParallelGroup(Alignment.BASELINE)
                                        .addComponent(lblTableFilter, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                        .addComponent(searchFilterField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addContainerGap())
        );
        searchPanel.setLayout(gl_searchPanel);

        searchFilterField.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {

                final String searchedWord = searchFilterField.getText();
                filter(searchedWord);

            }
        });

        scrollPane = new JScrollPane();
        add(scrollPane);

        //populate main table model with custom method
        populateMainTable(model);

        customerTable = new JTable(model);
        customerTable.setFillsViewportHeight(true);
        customerTable.setRowSelectionAllowed(true);

        THR.setHorizontalAlignment(SwingConstants.CENTER);

        customerTable.setDefaultRenderer(Object.class, renderer);
        customerTable.getTableHeader().setDefaultRenderer(THR);
        customerTable.setFont(new Font("Dialog", Font.PLAIN, 14));
        customerTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        customerTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        customerTable.setBackground(new Color(245, 245, 245));
        customerTable.addMouseListener(openCustomerListener());
        scrollPane.setViewportView(customerTable);

        //change component orientation with locale.
        if (bean.getLocale().toString().equals("ar_IQ")) {
            componentOrientation.changeOrientationOfJPanelToRight();
        } else {
            componentOrientation.changeOrientationOfJPanelToLeft();
        }
        //inject action event to Customers detail window to save all changes
        custWindow.setActionListener(saveChanges());
        this.setVisible(true);
    }
 
Example 20
Source Project: wpcleaner   File: Utilities.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a JTextField.
 * 
 * @param value Default value.
 * @param columns Number of columns.
 * @return JTextField.
 */
public static JTextField createJTextField(String value, int columns) {
  JTextField text = new JTextField(value, columns);
  text.addKeyListener(new CopyPasteListener(text));
  return text;
}