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

The following examples show how to use javax.swing.JTextField#selectAll() . 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 File: NamesAssociationDialog.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    associationModel.addAlias("...");
    removeButton.setEnabled(true);
    aliasNameScrollPane.repaint();
    int rowIndex = 0;
    for (String aliasName : associationModel.getAliasNames()) {
        if (aliasName.equals("...")) {
            break;
        }
        rowIndex++;
    }
    DefaultCellEditor editor = (DefaultCellEditor) aliasNames.getCellEditor(rowIndex, 0);
    aliasNames.editCellAt(rowIndex, 0);
    final JTextField textField = (JTextField) editor.getComponent();
    textField.requestFocus();
    textField.selectAll();
}
 
Example 2
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * GUI������������
 */
private void initGUI() {
    setLayout(new BorderLayout());

    // ���b�Z�[�W����\���G���A
    dialogueArea = new JTextArea();
    dialogueArea.setEditable(false);
    dialogueArea.setLineWrap(true);
    dialogueArea.append("�l�H���]�v���g�^�C�v\n\n");

    // ���b�Z�[�W���̓t�B�[���h
    inputField = new JTextField("���b�Z�[�W����͂��Ă�������");
    inputField.selectAll();

    // �p�l���ɒlj�
    JScrollPane scrollPane = new JScrollPane(dialogueArea);
    scrollPane.setAutoscrolls(true);
    add(scrollPane, BorderLayout.CENTER);
    add(inputField, BorderLayout.SOUTH);

    inputField.addActionListener(this);
}
 
Example 3
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * GUI������������
 */
private void initGUI() {
    setLayout(new BorderLayout());

    // ���b�Z�[�W����\���G���A
    dialogueArea = new JTextArea();
    dialogueArea.setEditable(false);
    dialogueArea.setLineWrap(true);
    dialogueArea.append("�l�H���]�v���g�^�C�v\n\n");

    // ���b�Z�[�W���̓t�B�[���h
    inputField = new JTextField("���b�Z�[�W����͂��Ă�������");
    inputField.selectAll();

    // �p�l���ɒlj�
    JScrollPane scrollPane = new JScrollPane(dialogueArea);
    scrollPane.setAutoscrolls(true);
    add(scrollPane, BorderLayout.CENTER);
    add(inputField, BorderLayout.SOUTH);

    inputField.addActionListener(this);
}
 
Example 4
Source File: FindDialog.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
@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 5
Source File: MemoryMapPluginTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void editNameCell(final JTable table, String name) {
	final int nameColumn = MemoryMapModel.NAME;
	final int namedRow = getNamedRow(table, nameColumn, name);

	runSwing(() -> {
		table.getSelectionModel().setSelectionInterval(namedRow, namedRow);
		table.scrollRectToVisible(table.getCellRect(namedRow, nameColumn, true));
	});

	Rectangle rect = table.getCellRect(namedRow, nameColumn, true);
	Point tablePoint = table.getLocationOnScreen();
	final int x = tablePoint.x + rect.x + (rect.width / 2);
	final int y = tablePoint.y + rect.y + (rect.height / 2);
	runSwing(() -> {
		MouseEvent editMouseEvent = new MouseEvent(table, MouseEvent.MOUSE_CLICKED,
			System.currentTimeMillis(), 0, x, y, 2, false);
		table.editCellAt(namedRow, nameColumn, editMouseEvent);
	});

	assertEquals(true, table.isEditing());

	Component editorComponent = table.getEditorComponent();
	assertNotNull(editorComponent);
	assertTrue(editorComponent instanceof JTextField);
	final JTextField editorField = (JTextField) editorComponent;
	editorField.selectAll();
	runSwing(() -> editorField.requestFocus());
	waitForPostedSwingRunnables();

	triggerText(editorField, ".myText\n");

	assertEquals(".myText", table.getModel().getValueAt(namedRow, nameColumn));
}
 
Example 6
Source File: DecimalCellEditor.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
                                             int column) {
    JComponent component = (JComponent) super.getTableCellEditorComponent(table, value, isSelected, row,
                                                                          column);
    final JTextField textField = (JTextField) component;
    textField.selectAll();
    textField.setBorder(defaultBorder);
    textField.setHorizontalAlignment(JTextField.RIGHT);
    return component;
}
 
Example 7
Source File: MeasurementSetPanel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent evt) { 
   measurementSetModel.addMeasurement(DEFAULT_MEASUREMENT_NAME); 

   // See comments in EditMeasurementNameActionAndFocusListener below...
   int lastIndex = measurementSetModel.getMeasurementSet().getSize()-1;
   JTextField textField = getMeasurementNameTextField(lastIndex);
   textField.requestFocus();
   textField.selectAll();
}
 
Example 8
Source File: ConnectionType.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void focusGained(FocusEvent focusEvent) {
    if(selectOnFocusFields == null) return;
    for (JTextField txt : selectOnFocusFields) {
        if(focusEvent.getSource()==txt) {
            txt.selectAll();
        }
    }
}
 
Example 9
Source File: LabelCellEditor.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
        int row, int column) {
  JTextField textField = (JTextField) getComponent();
  if (isSelected)
    textField.selectAll();

  return textField;
}
 
Example 10
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void addPauseTime(JToolBar mainToolBar, Insets margin) {
	pauseTime = new JTextField("0000-00-00T00:00:00") {
		@Override
		protected void processFocusEvent(FocusEvent fe) {
			if (fe.getID() == FocusEvent.FOCUS_LOST) {
				GUIFrame.this.setPauseTime(this.getText());
			}
			else if (fe.getID() == FocusEvent.FOCUS_GAINED) {
				pauseTime.selectAll();
			}
			super.processFocusEvent( fe );
		}
	};

	pauseTime.setPreferredSize(new Dimension(pauseTime.getPreferredSize().width,
			pauseTime.getPreferredSize().height));

	pauseTime.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent evt) {
			GUIFrame.this.setPauseTime(pauseTime.getText());
			controlStartResume.requestFocusInWindow();
		}
	});

	pauseTime.setText("");
	pauseTime.setHorizontalAlignment(JTextField.RIGHT);
	pauseTime.setToolTipText(formatToolTip("Pause Time",
			"Time at which to pause the run, e.g. 3 h, 10 s, etc."));

	mainToolBar.add(pauseTime);
}
 
Example 11
Source File: InitializrProjectPanelVisual1.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
@Override
public void focusGained(FocusEvent e) {
    if (e.getSource() instanceof JTextField) {
        JTextField tf = (JTextField) e.getSource();
        tf.selectAll();
    }
}
 
Example 12
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void addSnapToGridField(JToolBar buttonBar, Insets margin) {

		gridSpacing = new JTextField("1000000 m") {
			@Override
			protected void processFocusEvent(FocusEvent fe) {
				if (fe.getID() == FocusEvent.FOCUS_LOST) {
					GUIFrame.this.setSnapGridSpacing(this.getText().trim());
				}
				else if (fe.getID() == FocusEvent.FOCUS_GAINED) {
					gridSpacing.selectAll();
				}
				super.processFocusEvent( fe );
			}
		};

		gridSpacing.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				GUIFrame.this.setSnapGridSpacing(gridSpacing.getText().trim());
				controlStartResume.requestFocusInWindow();
			}
		});

		gridSpacing.setMaximumSize(gridSpacing.getPreferredSize());
		int hght = snapToGrid.getPreferredSize().height;
		gridSpacing.setPreferredSize(new Dimension(gridSpacing.getPreferredSize().width, hght));

		gridSpacing.setHorizontalAlignment(JTextField.RIGHT);
		gridSpacing.setToolTipText(formatToolTip("Snap Grid Spacing",
				"Distance between adjacent grid points, e.g. 0.1 m, 10 km, etc."));

		gridSpacing.setEnabled(snapToGrid.isSelected());

		buttonBar.add(gridSpacing);
	}
 
Example 13
Source File: FilterDialog.java    From WhiteRabbit with Apache License 2.0 4 votes vote down vote up
@Override
public void focusGained(FocusEvent e) {
	// TODO Auto-generated method stub
	JTextField jtf = (JTextField) e.getComponent();
	jtf.selectAll();
}
 
Example 14
Source File: NewResourceDialog.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void initGuiComponents(){
  this.getContentPane().setLayout(new BoxLayout(this.getContentPane(),
                                                BoxLayout.Y_AXIS));

  //name field
  Box nameBox = Box.createHorizontalBox();
  nameBox.add(Box.createHorizontalStrut(5));
  nameBox.add(new JLabel("Name: "));
  nameBox.add(Box.createHorizontalStrut(5));
  nameField = new JTextField(30);
  nameField.setMaximumSize(
      new Dimension(Integer.MAX_VALUE, nameField.getPreferredSize().height));
  nameField.setRequestFocusEnabled(true);
  nameField.selectAll();
  nameField.setVerifyInputWhenFocusTarget(false);
  nameBox.add(nameField);
  nameField.setToolTipText("Enter a name for the resource");
  
  nameBox.add(Box.createHorizontalStrut(5));
  nameBox.add(Box.createHorizontalGlue());
  this.getContentPane().add(nameBox);
  this.getContentPane().add(Box.createVerticalStrut(5));

  //parameters table
  parametersEditor = new ResourceParametersEditor();
  tableScroll = new JScrollPane(parametersEditor);
  this.getContentPane().add(tableScroll);
  this.getContentPane().add(Box.createVerticalStrut(5));
  this.getContentPane().add(Box.createVerticalGlue());
  //buttons box
  JPanel buttonsBox = new JPanel();
  buttonsBox.setLayout(new BoxLayout(buttonsBox, BoxLayout.X_AXIS));
  buttonsBox.add(Box.createHorizontalStrut(10));
  buttonsBox.add(okBtn = new JButton("OK"));
  buttonsBox.add(Box.createHorizontalStrut(10));
  buttonsBox.add(cancelBtn = new JButton("Cancel"));
  buttonsBox.add(Box.createHorizontalStrut(10));
  buttonsBox.add(helpBtn = new JButton("Help"));
  buttonsBox.add(Box.createHorizontalStrut(10));
  this.getContentPane().add(buttonsBox);
  this.getContentPane().add(Box.createVerticalStrut(5));
  setSize(400, 300);

  getRootPane().setDefaultButton(okBtn);
}
 
Example 15
Source File: AddJspWatchAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void performAction () {
        ResourceBundle bundle = NbBundle.getBundle (AddJspWatchAction.class);

        JPanel panel = new JPanel();
        panel.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_WatchPanel")); // NOI18N
        JTextField textField;
        JLabel textLabel = new JLabel (bundle.getString ("CTL_Watch_Name")); // NOI18N
        textLabel.setBorder (new EmptyBorder (0, 0, 0, 10));
        panel.setLayout (new BorderLayout ());
        panel.setBorder (new EmptyBorder (11, 12, 1, 11));
        panel.add ("West", textLabel); // NOI18N
        panel.add ("Center", textField = new JTextField (25)); // NOI18N
        textField.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); // NOI18N
        textField.setBorder (
            new CompoundBorder (textField.getBorder (), 
            new EmptyBorder (2, 0, 2, 0))
        );
        textLabel.setDisplayedMnemonic (
            bundle.getString ("CTL_Watch_Name_Mnemonic").charAt (0) // NOI18N
        );


        String t = null;//Utils.getELIdentifier();
//        Utils.log("Watch: ELIdentifier = " + t);
        
        boolean isScriptlet = Utils.isScriptlet();
        Utils.log("Watch: isScriptlet: " + isScriptlet);
        
        if ((t == null) && (isScriptlet)) {
            t = Utils.getJavaIdentifier();
            Utils.log("Watch: javaIdentifier = " + t);
        }
        
        if (t != null) {
            textField.setText(t);
        } else {
            textField.setText(watchHistory);
        }
        textField.selectAll ();        
        textLabel.setLabelFor (textField);
        textField.requestFocus ();

        org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor (
            panel, 
            bundle.getString ("CTL_Watch_Title") // NOI18N
        );
        dd.setHelpCtx (new HelpCtx ("debug.add.watch"));
        Dialog dialog = DialogDisplayer.getDefault ().createDialog (dd);
        dialog.setVisible(true);
        dialog.dispose ();

        if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
        String watch = textField.getText();
        if ((watch == null) || (watch.trim ().length () == 0)) {
            return;
        }
        
        String s = watch;
        int i = s.indexOf (';');
        while (i > 0) {
            String ss = s.substring (0, i).trim ();
            if (ss.length () > 0)
                DebuggerManager.getDebuggerManager ().createWatch (ss);
            s = s.substring (i + 1);
            i = s.indexOf (';');
        }
        s = s.trim ();
        if (s.length () > 0)
            DebuggerManager.getDebuggerManager ().createWatch (s);
        
        watchHistory = watch;
        
        // open watches view
//        new WatchesAction ().actionPerformed (null); TODO
    }
 
Example 16
Source File: ContrastPanel.java    From 3Dscript with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void focusGained(FocusEvent e) {
	JTextField tf = (JTextField)e.getSource();
	tf.selectAll();
}
 
Example 17
Source File: DoubleSlider.java    From 3Dscript with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void focusGained(FocusEvent e) {
	JTextField tf = (JTextField)e.getSource();
	tf.selectAll();
}
 
Example 18
Source File: TransformationPanel.java    From 3Dscript with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void focusGained(FocusEvent e) {
	JTextField tf = (JTextField)e.getSource();
	tf.selectAll();
}
 
Example 19
Source File: SingleSlider.java    From 3Dscript with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void focusGained(FocusEvent e) {
	JTextField tf = (JTextField)e.getSource();
	tf.selectAll();
}
 
Example 20
Source File: ExtTestCase.java    From netbeans with Apache License 2.0 3 votes vote down vote up
private static boolean tryDispatchingKeystrokes(final JTextField j) throws Exception {
    requestFocus(j);
    j.selectAll();
    sleep();
    
    pressKey(j, KeyEvent.VK_SHIFT);
    
    typeString("HELLO", j);
    
    releaseKey(j, KeyEvent.VK_SHIFT);
    
    System.err.println("Text area text is now " + j.getText());
    
    return "HELLO".equals(j.getText());
}