Example usage for javax.swing JTextField setText

List of usage examples for javax.swing JTextField setText

Introduction

In this page you can find the example usage for javax.swing JTextField setText.

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified text.

Usage

From source file:org.eclipse.swt.snippets.Snippet300.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("SWT and Swing DND Example");
    GridLayout layout = new GridLayout(1, false);
    shell.setLayout(layout);// www .  j  av a  2  s  .co m

    Text swtText = new Text(shell, SWT.BORDER);
    swtText.setText("SWT Text");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    swtText.setLayoutData(data);
    setDragDrop(swtText);

    Composite comp = new Composite(shell, SWT.EMBEDDED);
    java.awt.Frame frame = SWT_AWT.new_Frame(comp);
    JTextField swingText = new JTextField(40);
    swingText.setText("Swing Text");
    swingText.setDragEnabled(true);
    frame.add(swingText);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = swingText.getPreferredSize().height;
    comp.setLayoutData(data);

    shell.setSize(400, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:DnDDemo2.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new JPanel());

    JTextField textField = new JTextField(25);
    textField.setText("Let's swing higher");
    frame.add(textField);/*from  ww  w  . ja v  a2s  .c  o  m*/

    JTextArea textArea = new JTextArea("Demonstrating\ndrag and drop");
    textArea.setForeground(Color.red);
    frame.add(new JScrollPane(textArea));

    textArea.setDragEnabled(true);
    textField.setDragEnabled(true);
    TextColorTransferHandler transferHandler = new TextColorTransferHandler();
    textArea.setTransferHandler(transferHandler);
    textField.setTransferHandler(transferHandler);
    frame.pack();
    frame.setVisible(true);
}

From source file:KeyTextComponent.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Key Text Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    KeyTextComponent keyTextComponent = new KeyTextComponent();
    final JTextField textField = new JTextField();
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String keyText = actionEvent.getActionCommand();
            textField.setText(keyText);
        }//www.j  a  v a 2 s.c  o  m
    };
    keyTextComponent.addActionListener(actionListener);
    frame.add(keyTextComponent, BorderLayout.CENTER);
    textField.setText("Press keyboard after clicking the above blank area");
    frame.add(textField, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Key Text Sample");
    KeyTextComponent keyTextComponent = new KeyTextComponent();
    final JTextField textField = new JTextField();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String keyText = actionEvent.getActionCommand();
            textField.setText(keyText);
        }//from   w  w  w  . j  ava 2s  . c o m
    };
    keyTextComponent.addActionListener(actionListener);
    frame.add(keyTextComponent, BorderLayout.CENTER);
    frame.add(textField, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Label Focus Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);
    JTextField textField = new JTextField();
    label.setLabelFor(textField);//from  w w  w  .j  a v a2 s . co m
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    frame.setSize(250, 150);
    frame.setVisible(true);

    textField.setText("Loooooooooooooooooooooooooooooooooooooooooooooooooooooooong");
    BoundedRangeModel model = textField.getHorizontalVisibility();
    int extent = model.getExtent();
    textField.setScrollOffset(extent);
    System.out.println("extent:" + extent);

}

From source file:KeyTextTester.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Key Text Sample");
    KeyTextComponent keyTextComponent = new KeyTextComponent();
    final JTextField textField = new JTextField();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String keyText = actionEvent.getActionCommand();
            textField.setText(keyText);
        }/*from www . java 2 s. c  o  m*/
    };
    keyTextComponent.addActionListener(actionListener);

    Container contentPane = frame.getContentPane();
    contentPane.add(keyTextComponent, BorderLayout.CENTER);
    contentPane.add(textField, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Key Text Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    KeyTextComponent keyTextComponent = new KeyTextComponent();
    final JTextField textField = new JTextField();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String keyText = actionEvent.getActionCommand();
            textField.setText(keyText);
        }/*from  w w w . j  a va 2s  . c  om*/
    };
    keyTextComponent.addActionListener(actionListener);

    frame.add(keyTextComponent, BorderLayout.CENTER);
    frame.add(textField, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:KeyTextTester2.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Key Text Sample");
    KeyTextComponent2 keyTextComponent = new KeyTextComponent2();
    final JTextField textField = new JTextField();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String keyText = actionEvent.getActionCommand();
            textField.setText(keyText);
        }/*from  ww w.j a  v a2  s  . c o  m*/
    };
    keyTextComponent.addActionListener(actionListener);

    Container contentPane = frame.getContentPane();
    contentPane.add(keyTextComponent, BorderLayout.CENTER);
    contentPane.add(textField, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Type tab to and then type");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    KeyTextComponent keyTextComponent = new KeyTextComponent();
    final JTextField textField = new JTextField();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String keyText = actionEvent.getActionCommand();
            textField.setText(keyText);
        }/* www.j av  a 2s.c  o  m*/
    };
    keyTextComponent.addActionListener(actionListener);

    frame.add(keyTextComponent, BorderLayout.CENTER);
    frame.add(textField, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String items[] = { "Item1", "item1" };
    JFrame f = new JFrame();
    JPanel panel = new JPanel();
    JComboBox<String> combo = new JComboBox<>(items);
    combo.setEditable(true);//from   ww  w .j  a  v  a  2 s  .  c o m

    JTextField txt = new JTextField(10);
    panel.add(combo);
    panel.add(txt);
    f.add(panel);
    combo.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent ie) {
            String str = (String) combo.getSelectedItem();
            txt.setText(str);
        }
    });
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(400, 100);
    f.setVisible(true);
}