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
9
votes
6 answers

Auto-Completing JTextField and Arrow Keys

I'm trying to build a javax.swing.JTextField with javax.swing.JList for auto-completing like Google. When a write a word, Google show several matches and when a press the   ▼   I can select some match using   ▲   and   ▼   and can edit my…
Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
8
votes
4 answers

How can I get the length of a JTextField's contents as the user types?

JTextField has a keyTyped event but it seems that at the time it fires the contents of the cell have not yet changed. Because of that .length() is always wrong if read here. There must be a simple way of getting the length as it appears to the user…
Allain Lalonde
  • 91,574
  • 70
  • 187
  • 238
8
votes
1 answer

Adding textfield to Graphics in java

Does anyone know how to add JTextField into Graphics name bufferstrategy.getDrawGraphics? Tryed to pain it into graphics, something like this: private JTextField Input = new JTextField(); BufferStrategy bs = getBufferStrategy(); if (bs == null)…
null
  • 87
  • 1
  • 7
8
votes
5 answers

JTextField in which the predefined text in not editable but other text can be appended to it?

While going through Java swing I faced this problem. I have a JTextField which has predefined and not editable text. the user should be able to append other text to it but without editing the predefined text. Is there any method to obtain this…
sanjeeda
  • 131
  • 1
  • 10
8
votes
3 answers

Not able to add JTextField to JFrame

I am not able to add JTextField to JFrame. My JFrame contains a JLabel and a JTextField . First, i have added the JLabel, and it is working. Here is the code. private static void createandshowGUI() { JFrame frame =new…
Sam
  • 364
  • 2
  • 6
  • 17
8
votes
3 answers

How to display a default message in JTextField java

I want to create a JTextField with a message inside as a deafult. But not as a proper text but as a comment about what to type inside the JTextField. So if i type jtf.getText() it returns null or empty because it is just a comment that was printed…
Gustavo Baiocchi Costa
  • 1,379
  • 3
  • 16
  • 34
8
votes
3 answers

Filtering JList based on JTextField

I have a JTextField and a JList in my program. The JList contains the user's contacts. I'd like to filter the JList based on the text on the JTextField. For example, if I type in "Mike" it will only show contacts including "Mike". When the user…
MikkoP
  • 4,864
  • 16
  • 58
  • 106
8
votes
7 answers

how to make a jtextfield having a fixed date format?

I'm having trouble creating a fixed date format using JTextField. Is there a way for JTextField to have a fixed date format ?
Janpol Seda
  • 81
  • 1
  • 1
  • 3
8
votes
10 answers

How to clear a string?

In a program I'm working on, a textfield has to display some text at some point. output.setText( outputString ); outputString = ""; output is a JTextField. These lines of code are in a method, and when it is called the first time, it works…
kullalok
  • 813
  • 2
  • 13
  • 19
7
votes
3 answers

Deselect default selection on JTextfield

When using JTextFields i like to set a default text. Then i run the program and this default text will automatically be selected (at least when you have only one field). In other words, if I type a letter right away, the default text will be deleted…
Ole-M
  • 821
  • 2
  • 13
  • 27
7
votes
1 answer

How to create a Jlabel inside JTextArea like in Facebook?

Is there a way I can create a JTextArea or JTextField with some JLabels inside it, like in this screenshot from Facebook: What I am trying to do is put some JButtons with titles like "Apple", "Orange", ... When user clicks on a JButton of those,…
Brad
  • 4,457
  • 10
  • 56
  • 93
7
votes
6 answers

Adding JTextField to a JPanel and showing them

I'm building a little app using Java and Swing in NetBeans. Using NetBeans design window, I created a JFrame with a JPanel inside. Now I want to dynamically add some jTextFields to the JPanel. I wrote something like that: Vector textFieldsVector =…
Davide Gualano
  • 12,813
  • 9
  • 44
  • 65
7
votes
7 answers

Example text in JTextField

I am looking for a way to put example text into a swing JTextField and have it grayed out. The example text should then disappear as soon as any thing is entered into that text field. Some what similar to what stackoverflow does when a user is…
startoftext
  • 3,846
  • 7
  • 40
  • 49
7
votes
2 answers

Copy text from a disabled JTextField

Is it possible to allow a user to copy text from within a disabled JTextField? At the moment if I have a text field that is disabled, the user is unable to select the text to copy and paste into another app.
digiarnie
  • 22,305
  • 31
  • 78
  • 126
7
votes
2 answers

Make JTable cell editor value be selectable, but not editable?

I have tried to keep my JTable's tight and secure, making only editable columns editable via isCellEditable(). However, my clients are insisting that they want to double click on a cell so they can copy its contents, even if it is read only. I could…
tmn
  • 11,121
  • 15
  • 56
  • 112