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

Making a JTextField background transparent

I'm trying to make the background for a JTextField transparent, that way so the JLabel underneath it is still visible, but whenever entering text into the JTextField you can see the text. Here's what I have now basically. The JTextField background…
RuneRebellion
  • 149
  • 1
  • 2
  • 12
6
votes
1 answer

jgoodies binding: using a JTextField with a formatted number?

I am trying to bind a JTextField to a bean's field that is a double using JGoodies Binding: JTextField myJTextField = ... BeanAdapter adapter =…
Jason S
  • 184,598
  • 164
  • 608
  • 970
6
votes
3 answers

What is the best way to position the caret at the end of a JTextField on focus?

By default, when a JTextField gains focus the caret is positioned at the beginning of the text. However, I think the better behavior is to position it at the end, or to select all the text, e.g. http://jsfiddle.net/Marcel/jvJzX/. What is a nice way…
Peter Tseng
  • 13,613
  • 4
  • 67
  • 57
6
votes
3 answers

How do I center a JTextfield

I'm having trouble centering a JTexfield in my program.The Textfield does not appear aligned with the JButton. I've tried using the x.setHoriontalAlignment(JTextfield.CENTER); but to no avail. Any ideas? import java.awt.Color; import…
NABIL SHAHIN
  • 61
  • 1
  • 1
  • 2
6
votes
4 answers

Limiting Length of Input in JTextField is not working

I am trying to limit the max length of character a user can input in a textfield but It seems to be not working. Here is the code: text2 = new JTextField("Enter text here",8); Is there anything I am doing wrong? How can I make the limit to work…
Naruto
  • 1,710
  • 7
  • 28
  • 39
6
votes
3 answers

German characters in JTextField

I'm working on a Java application for people learning German, and I have run into a problem with the special characters of this language. I want to make a subclass of JTextField that will interpret ALT + a as ä, ALT + o as ö and so on, while…
KCH
  • 2,794
  • 2
  • 23
  • 22
6
votes
3 answers

How to simulate Keyboard press in java

I want to simulate entering a string (can contain any character) in JTextField. I am using new KeyEventData() for that. But I am not able to determine how to handle characters like {, }, ) etc and also how to append a new character to already…
user1247412
  • 647
  • 7
  • 16
  • 29
6
votes
4 answers

Best way to constrain user to enter a time in a JTextField

In one of my java applications, there is a field where the user is supposed to enter a time. I know, I can simply keep it as a normal JTextField and at the time of validation I can check the value and so on... But I think there is a better way than…
Anubis
  • 6,995
  • 14
  • 56
  • 87
6
votes
2 answers

Dynamically resize JTextField in JTree Node

I am using a JPanel with some JLabels and JTextFields as editor and renderer in a JTree. The user can click on any JTextField and modify the text. All works fine. All I am missing is how I can dynamically resize (grow) the JTextField as the user is…
Torsten Römer
  • 3,834
  • 4
  • 40
  • 53
6
votes
2 answers

JTextField: How to limit the number of characters?

Please have a look at the following code. import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.*; import javax.swing.text.AbstractDocument; import javax.swing.text.AttributeSet; import…
PeakGen
  • 21,894
  • 86
  • 261
  • 463
5
votes
2 answers

Select all text in editable JComboBox and set cursor position

public class CursorAtStartFocusListener extends FocusAdapter { @Override public void focusGained(java.awt.event.FocusEvent evt) { Object source = evt.getSource(); if (source instanceof JTextComponent) { JTextComponent comp =…
Karen
  • 1,025
  • 1
  • 10
  • 22
5
votes
3 answers

Move cursor of JTextField or JComboBox to the start

I have a JTextField with some text. When I click text field the cursor moves to the end of field. I want the cursor to move to the start of the field when it becomes focused. I have the same problem with an editable JComboBox. How can I achieve…
Karen
  • 1,025
  • 1
  • 10
  • 22
5
votes
2 answers

JTextField uneditable in JWindow

I have a Jwindow, and when I added a Jtextfield to it, the textfield became uneditable. JWindow window = new JWindow(); window.setBounds(400, 100, 700,500); window.setVisible(true); window.setLayout(null); JTextField text = new…
TU_HEO DAKAI
  • 2,197
  • 8
  • 28
  • 39
5
votes
2 answers

Show Event for JTextField in Java?

I'm implementing a specialized version of JTextField and want to pack it into an own bean. The bean works pretty fine so far. Here's my question: How can I detect when the JTextField is shown? So that I can init some graphical stuff everytime the…
salocinx
  • 3,715
  • 8
  • 61
  • 110
5
votes
2 answers

Make a program automatically add text fields in java

Maybe there is a similar question to this, but I couldn't find a one. Id like my program ( awt or swing ) to add controls ( like text fields ) automatically. For example : A dialog program has 10 fields for inputting names, but I need 11 so by…
Ikspeto
  • 582
  • 6
  • 12