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
19
votes
2 answers

How to display faint gray "ghost text" in a JTextField?

I don't know if I got the right name for it, but I'm looking to see if there is a specific way to implement a text field so that while it doesn't have focus and is empty, a faint gray string of text is displayed in the field. When the field is…
jez
  • 1,239
  • 1
  • 7
  • 14
18
votes
4 answers

Hide/Show Password in a JTextFIeld (Java Swing)

So I've been working on a Password Strength Checker and the way it works is that the user enters some random text into a textfield and then instantaneous visual feedback (breakdown of points) is displayed. I've also added a checkbox, which on being…
Manas Bajaj
  • 1,133
  • 3
  • 16
  • 26
17
votes
3 answers

how to find source component that generated a DocumentEvent

Is it possible to discover which oject generated a DocumentEvent? Something like i can do with ActionListener: JTextField field = new JTextField(""); field.addActionListener(actionListener); //inside ActionListener public void…
Heisenbug
  • 38,762
  • 28
  • 132
  • 190
16
votes
4 answers

JTextField only shows as a slit Using GridBagLayout, need help

Hi thank you in advance for any help, I'm trying to build a simple program to learn GUI's but when I run the code below my JTextFields all show as a slit thats not large enough for even one character. cant post an image but it would look similar to:…
Bill.Caffery
  • 465
  • 1
  • 5
  • 21
14
votes
2 answers

Is it possible to have an autocomplete using jtextfield and a Jlist?

I want to create an auto-complete program in java which should provide a list of suggestions instantly when the user types a character/String inside a JTextfield. The problem is that I am confused on how to do it. Could somebody provide an idea or…
papski
  • 1,241
  • 5
  • 28
  • 52
14
votes
2 answers

JTextField setEnabled vs setEditable

What is the difference between JTextField.setEnabled() and JTextField.setEditable()? In my code I have an Instance of a class inherited from JTextField. But when I set its property setEnabled(false) I can still edit and process its contents in my…
Tariq
  • 2,489
  • 11
  • 36
  • 61
14
votes
3 answers

How to adjust alignment to right for a text entered in the JTextField

I want to set the alignment of my text to right. Actually the fields are related to currency so if it starts from right, it will look good. PreparedStatement stmt1 = con.prepareStatement("select sum(tv)as totalsum from mut_det WHERE rm_id = ?"); …
user1951149
  • 155
  • 1
  • 2
  • 8
13
votes
1 answer

How to clear the JTextField by clicking JButton

Possible Duplicate: JButton needs to change JTextfield text How do I clear a JTextField when a JButton is clicked?
Monte
  • 131
  • 1
  • 1
  • 3
13
votes
4 answers

How to UnFocus a JTextField

When my application loads, which is made using netbeans, the first JTextField is automatically focused, and in this JTextField, I have written "Enter your Username", it will go away when the user clicks on this field, but when the application is…
Ali Bassam
  • 9,691
  • 23
  • 67
  • 117
12
votes
5 answers

How to allow introducing only digits in jTextField?

I have tried to use the example shown here but java showing error message of "AttributeSet cannot be resolved to a type" That is why I am trying to use another method of allowing only digits: txtUsername.addKeyListener(new…
Bakhtiyor
  • 7,198
  • 15
  • 55
  • 77
12
votes
5 answers

How to implement in Java ( JTextField class ) to allow entering only digits?

How to implement in Java ( JTextField class ) to allow entering only digits?
Damir
  • 54,277
  • 94
  • 246
  • 365
12
votes
9 answers

How to set the height and the width of a textfield in Java?

I was trying to make my JTextField fill the width and set a height for it but still failed. I tried adding the code setPreferredSize(new Dimension(320,200)); but still failed. Is there any way I can make my JTextField fill the width and set the…
Ms. B
  • 1,073
  • 6
  • 15
  • 26
12
votes
7 answers

How to clear JTextField when mouse clicks the JTextField

I need to make this program clear the text from the text field when the mouse clicks in that text field. I have tried a few things, but none of them have yet to work for me. Here is the code in its entirety: public class TimerClassPanel extends…
Joshua Vaughan
  • 347
  • 3
  • 7
  • 16
11
votes
1 answer

How to show Bengali text properly

I have a JTextArea where I need to show Bengali text like: বাংলাদেশ But all I can see is rectangular boxes. How can I show Bengali characters properly?
user1362827
10
votes
5 answers

JTextField Fixed Height

How do I get the JTextField to have a fixed height when the Frame is maximized? I want it to look sort of similar to the Skype application on Ubuntu. private JTextField username; private JPasswordField password; private JLabel…
unleashed
  • 109
  • 1
  • 1
  • 4