Questions tagged [jtextfield]

JTextField is a Java Swing component that allows the editing of a single line of text.

JTextField is a lightweight component that allows the editing of a single line of text. For information on and examples of using text fields, see How to Use Text Fields in The Java Tutorial.

2960 questions
5
votes
1 answer

How to insert a 'String' in a 'JTextField' to a specific position?

I want to insert a String in a JTextField. Something like- myTextField.insert(text, position); How can it be done? Is there any simple way to do this?
Mad_Matt
  • 75
  • 1
  • 5
5
votes
2 answers

Adding a prompt text property to JTextfield

I am using Netbeans IDE. I want to give the prompt text to JTextfield in such a way that when user enters the text into JTextField it gets cleared and accepts the users input.
Jayashri
  • 366
  • 4
  • 13
  • 25
5
votes
4 answers

Convert JTextField input into an Integer

I am new to JAVA, I am trying to convert an input from a JTextField into an integer, I have tried loads of options but nothing is working, the eclipse is always giving me an error and the errors are not making sense to me. import java.awt.Graphics; …
MBC870
  • 373
  • 3
  • 8
  • 16
5
votes
4 answers

java documentlistener

I'm trying to call method after changing text of JTextField. textField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { …
Sergey Scopin
  • 2,217
  • 9
  • 39
  • 67
5
votes
4 answers

JTextField displayed as slit when using FlowLayout...please explain

Can someone please explain to me, why every time I use the FlowLayout Layout manager my textfields are displayed as slits. I have bumped my head against this problem for some time now, and I can't seem to figure out why it goes wrong. I get a…
TrashCan
  • 817
  • 4
  • 13
  • 20
5
votes
2 answers

loop through JPanel

In order to initialize all JTextfFields on a JPanel when users click a "clear button", I need to loop through the JPanel (instead of setting all individual field to ""). How can I use a for-each loop in order to iterate through the JPanel in search…
Dallag
4
votes
2 answers

Sizing issue with scrollable JTextField

I have a form with lots of text fields and some of those text fields may contain very long strings. To make it work I made those text fields scrollable using this code: JScrollPane scroll = new JScrollPane(textField); scroll.setPreferredSize(new…
GrayR
  • 1,395
  • 2
  • 19
  • 32
4
votes
4 answers

GUI Trouble reading JTextField

I can't figure out where I am going wrong with this, I have tried to changing a few things but I just can't get the "CalculateButtonHandler to work correctly. Sorry put out all this code but last time I wasn't specific enough :S If someone could…
ChewOnThis_Trident
  • 2,105
  • 2
  • 18
  • 22
4
votes
4 answers

Checking if a JTextfield is selected or not

Is it possible to check if a jtextfield has been selected / de-selected (ie the text field has been clicked and the cursor is now inside the field)? //EDIT thanks to the help below here is a working example import java.awt.event.FocusEvent; import…
Ricco
  • 775
  • 5
  • 11
  • 19
4
votes
5 answers

How can I select text over two different JTextField's?

Lets say I have this code: public static void main(final String [] args) { final JFrame frame = new JFrame("Display Keyword Panel"); final JPanel panel = new JPanel(new BorderLayout()); JTextField text1 = new JTextField("This is…
Grammin
  • 11,808
  • 22
  • 80
  • 138
4
votes
4 answers

select all on focus in lots of jTextField

I have lots of jTextFields in my application (About 34 jTextFields) and I want all of them select all of their text when get focus and select none of text on focus lost. Is there any way to do this with one listener or should I write a "FocusGained"…
Ariyan
  • 14,760
  • 31
  • 112
  • 175
4
votes
2 answers

Simple way to cancel user input on esc key pressed?

Is there a simple way to cancel the user input in a JTextField when key Esc is pressed ? I mean something different that a key listener and a data backup. Thanks
user777466
  • 991
  • 2
  • 13
  • 21
4
votes
3 answers

Problem with multi-line JTextField

I have a JTextField and need to have 3 lines in it, such as these: HI MY name is mehdi How can I set the text in a JTextField? I tried \n, but it didn't work.
Mahdi_Nine
  • 14,205
  • 26
  • 82
  • 117
4
votes
4 answers

How to set focus on specific JTextfield inside JOptionPane when created?

I want to set the focus on a specific JTextField which is passed to the JOptionPane as Object Message. Here is my code (I want the focus on txt2 but the focus always is on txt1): import java.awt.*; import java.util.*; import javax.swing.*; public…
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
4
votes
3 answers

Questions: controlling a Swing GUI from an external class and separating logic from user interface

UPDATE: I'm using Netbeans and Matise and it's possible that it could be Matise causing the problems I describe below. UPDATE 2: Thanks to those who offered constructive suggestions. After rewriting the code without Matise's help, the answer offered…
user187702