javax.swing.JTextField#addKeyListener ( )源码实例Demo

下面列出了javax.swing.JTextField#addKeyListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gcs   文件: Search.java
/**
 * 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);
}
 
源代码2 项目: netbeans   文件: FileCompletionPopup.java
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);
}
 
源代码3 项目: Forsythia   文件: PanJigTags.java
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);
  
}
 
源代码4 项目: jdk8u-jdk   文件: DeadKeyMacOSXInputText.java
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();

}
 
源代码5 项目: TencentKona-8   文件: FindPanel.java
protected void createDesign() {
    setLayout(new GridLayout());
    nameComboBox = new JComboBox();
    valueTextField = new JTextField();
    add(nameComboBox);
    add(valueTextField);
    valueTextField.addKeyListener(this);
}
 
源代码6 项目: hottub   文件: DeadKeyMacOSXInputText.java
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();

}
 
源代码7 项目: jdk8u60   文件: DeadKeyMacOSXInputText.java
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();

}
 
源代码8 项目: MtgDesktopCompanion   文件: UITools.java
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);
		
	}
 
源代码9 项目: FancyBing   文件: FindDialog.java
@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;
}
 
源代码10 项目: openjdk-jdk9   文件: DeadKeyMacOSXInputText.java
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();

}
 
源代码11 项目: openjdk-jdk8u   文件: FindPanel.java
protected void createDesign() {
    setLayout(new GridLayout());
    nameComboBox = new JComboBox();
    valueTextField = new JTextField();
    add(nameComboBox);
    add(valueTextField);
    valueTextField.addKeyListener(this);
}
 
源代码12 项目: Robot-Overlord-App   文件: LogPanel.java
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;
}
 
源代码13 项目: openvisualtraceroute   文件: ControlPanel.java
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());
}
 
源代码14 项目: jdk8u-dev-jdk   文件: DeadKeyMacOSXInputText.java
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();

}
 
源代码15 项目: rapidminer-studio   文件: AutoCompletionComboBox.java
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");
	}
}
 
源代码16 项目: openjdk-8   文件: FindPanel.java
protected void createDesign() {
    setLayout(new GridLayout());
    nameComboBox = new JComboBox();
    valueTextField = new JTextField();
    add(nameComboBox);
    add(valueTextField);
    valueTextField.addKeyListener(this);
}
 
源代码17 项目: bytecode-viewer   文件: RegexSearch.java
public RegexSearch()
{
    searchText = new JTextField("");
    searchText.addKeyListener(EnterKeyEvent.SINGLETON);
}
 
源代码18 项目: TrakEM2   文件: Tree.java
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);
}
 
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);
    }
 
源代码20 项目: wpcleaner   文件: Utilities.java
/**
 * 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;
}