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
246
votes
14 answers

Value Change Listener to JTextField

I want the message box to appear immediately after the user changes the value in the textfield. Currently, I need to hit the enter key to get the message box to pop out. Is there anything wrong with my code? textField.addActionListener(new…
user236501
  • 8,538
  • 24
  • 85
  • 119
115
votes
10 answers

Detect enter press in JTextField

Is it possible to detect when someone presses Enter while typing in a JTextField in java? Without having to create a button and set it as the default.
a sandwhich
  • 4,352
  • 12
  • 41
  • 62
58
votes
6 answers

Restricting JTextField input to Integers

I know that this question must have been asked and answered a million times, but I just can't find an easy solution. I have a JTextField that is meant to accept only positive integers as input. I need a way to make sure that nothing else gets input…
AndroidDev
  • 20,466
  • 42
  • 148
  • 239
51
votes
20 answers

Is there any way to accept only numeric values in a JTextField?

Is there any way to accept only numeric values in a JTextField? Is there any special method for this?
Johanna
  • 27,036
  • 42
  • 89
  • 117
49
votes
9 answers

Java JTextField with input hint

I would like to add a hint value to my javax.swing.JTextField. It should look like Firefox rendering of . This creates an edit field with the text 'bla' in the background. If the textbox has focus the title-text…
Wienczny
  • 3,958
  • 4
  • 30
  • 35
34
votes
6 answers

JTable - Selected Row click event

I have a Jtable that is populated with a linkedlist through an AbstractTableModel. What I want to do is when I click (left-mouse click) on a row in the JTable, the linkedlist is search (in this case it contains movie titles) and displays the values…
Brian
  • 1,951
  • 16
  • 56
  • 101
33
votes
12 answers

Java - Check if JTextField is empty or not

So I got know this is a popular question and already found the solution. But when I try this it doesn't work properly. My JTextField is empty and the button isn't enabled. When I write something in my textfield the button doesn't get enabled. So my…
ColdStormy
  • 562
  • 1
  • 6
  • 15
31
votes
10 answers

How to Set Focus on JTextField?

I make my game run without mouse so using pointer is not a choice. High Score menu will show when player lose. this is my code highScore=new MyTextField("Your Name"); highScore.addKeyListener(this); highScore.setFont(font); …
Kenjiro
  • 749
  • 1
  • 12
  • 33
30
votes
9 answers

Limiting the number of characters in a JTextField

I want to set the maximum length of a JTextField, so that you can't enter more characters than the limit. This is the code I have so far... textField = new JTextField(); textField.setBounds(40, 39, 105, 20); contentPane.add(textField); …
user1326088
29
votes
4 answers

java swing JTextField set PlaceHolder

I created a JTextField and now I want to set the placeholder on that JTextField, but I don't know how? Please help. Here is my code: JTextField database=new JTextField("Enter Data Base…
Renish Khunt
  • 5,620
  • 18
  • 55
  • 92
27
votes
6 answers

How can I add padding to a jtextfield

How can I add some padding to a jtextfield? I've tried tf.setMargin(new Insets(5,5,5,5)); which doesn't have any effect.
fenerlitk
  • 5,414
  • 9
  • 29
  • 39
26
votes
4 answers

How can I control the width of JTextFields in Java Swing?

I am trying to have several JTextFields on a single row, but I don't want them to have the same width. How can I control the width and make some of them wider than others? I want that they together take up 100% of the total width, so it would be…
Jonas
  • 121,568
  • 97
  • 310
  • 388
26
votes
7 answers

Swing JTextField how to remove the border?

Is there anyway to remove a border in a JTextField? txt = new JTextField(); txt.setBorder(null); // <-- this has no effect. I would really want it to look like a JLabel - but I still need it to be a JTextField because I want people to be able…
Markus V.
  • 347
  • 2
  • 4
  • 6
22
votes
5 answers

JTextField Issues with Numpad

I've recently run into a strange issue with the Java JTextField. When I run the following code (see below), typing a "0" into the text field first sends a paste action, then types "0". For example, if "text" is copied to the clipboard, "text0" is…
lrAndroid
  • 2,834
  • 18
  • 27
20
votes
8 answers

How to add text on jprogressbar?

I am using a jprogressbar to indicate the availability status. i want to display a text of 40%[assumption] inside the progressbar. how to do it? the text was changed according to the availability value
Siddhu
  • 1,188
  • 2
  • 14
  • 24
1
2 3
99 100