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
10
votes
3 answers

JTextArea and JTextField internal padding on text

I would like to increase the spacing / padding / insets for the JTextField and JTextArea. Effectively increase the spacing between the two red lines in the image below:
n002213f
  • 7,805
  • 13
  • 69
  • 105
10
votes
1 answer

swing: appropriate Listener for JTextField change events

Which type of Listener do I use for listening to changed text events in a JTextField? (I should know this or be able to tell from the Javadoc but I can't seem to figure it out.)
Jason S
  • 184,598
  • 164
  • 608
  • 970
10
votes
3 answers

JOptionPane with username and password input

I have my own Dialog pop up with two textfields, two JLabel and a "ok" JButton. The pop up is a login window. The window works perfect I just want to know how I am able to add a "cancel" JButton, so the user is able to cancel the login. Here is my…
Gerret
  • 2,948
  • 4
  • 18
  • 28
10
votes
3 answers

Force JTextField to select all of its contents when it appears

I have a JLabel that when you click on it its replaced with a JTextField. I need that JTextField to automatically select all of its text when it appears.
Benjamin Albert
  • 738
  • 1
  • 7
  • 19
9
votes
4 answers

Java Swing rounded border for Jtextfield

When I do : LineBorder lineBorder =new LineBorder(Color.white, 8, true); jTextField2.setBorder(lineBorder ); I get this result like: How can I have rounded borders without the squared corners visible and the text half cut ? Thank you very…
Vincent Roye
  • 2,751
  • 7
  • 33
  • 53
9
votes
3 answers

Let ActionListener listen for change in JTextField instead of only enter?

So as you may know, if you have a text field and you add an ActionListener to it, it will only listen to the keypress of the enter button. However, I want to let my ActionListener listen to changes in text of the . So basically I've got this: …
ZimZim
  • 3,291
  • 10
  • 49
  • 67
9
votes
2 answers

Decorating a JTextField with an image and hint

I'm trying to create some nicer looking JTextFields with an image and a hint. To do this I made a decorator that overrides the paintComponent method. The reason I used a decorator is that I wanted to apply it to other types of JTextField such as…
Aidan
  • 225
  • 1
  • 3
  • 11
9
votes
4 answers

How to convert JTextField to String and String to JTextField?

How to convert JTextField to String and String to JTextField in Java?
user733046
  • 101
  • 1
  • 1
  • 2
9
votes
5 answers

How to set a custom background color on a line in a JTextPane

I would like to alternate between gray and white as background from one line of my JTextPane to the next. I tried to do this by overloading the paintComponent() method and drawing the background manually according to component height an Font size…
jumar
  • 5,360
  • 8
  • 46
  • 42
9
votes
3 answers

How to increase the width of JTextField in Tab?

In Food Tab, I want to achieve this But I only able to get this How can I increase the width of the JTextField which are in Food Tab ? Below is my code public class FoodOrdering { static private JFrame frame; static private…
John Joe
  • 12,412
  • 16
  • 70
  • 135
9
votes
3 answers

how to get value on TextField Java Swing

I have a simple Java Swing form with a JTextField, I get value on JTextField by getText() method but I can't use it to main program. Can you help me What problem and how to fix? This is my code : import java.awt.*; import…
dientmUET
  • 101
  • 1
  • 1
  • 14
9
votes
1 answer

How to retain selected text in JTextField when focus lost?

Now finishing my custom menu popup, but the problem is that if I select some text in JTextField and click mouse button to show popup menu, then focus is transferred to popup window, AND selected text before are no longer highlighted. When focus is…
Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117
9
votes
3 answers

Java, Swing: how do I set the maximum width of a JTextField?

I'm writing a custom file selection component. In my UI, first the user clicks a button, which pops a JFileChooser; when it is closed, the absolute path of the selected file is written to a JTextField. The problem is, absolute paths are usually…
Leonel
  • 28,541
  • 26
  • 76
  • 103
9
votes
2 answers

How to make difference between textField.setText() and adding text to textField manually in java?

I have a textField in my application which will be initiated programmatically (textField.setText() ) when user clicked in an item in JList. later user will change this value manually. I get stuck with using document-listener to detect changes in…
itro
  • 7,006
  • 27
  • 78
  • 121
9
votes
2 answers

JTextField margin doesnt work with border

I have a JTextField and i want to setMargin. But when i set any border, it doesn' t properly work. It' s margin function doesn't work. This is my code; import java.awt.Color; import java.awt.Insets; import java.io.IOException; import…
querman
  • 135
  • 1
  • 2
  • 8