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

JTextField, using Document Filter to filter integers and periods

EDIT - added at then end of the post the answer we were able to achieve This is my first post in SO, so i hope i can ask everything right! I searched and didn't quite find a answer to my question despite similar questions being posted, so i hope…
Joao Bastos
  • 73
  • 1
  • 1
  • 4
7
votes
3 answers

Setting text background color?

How can I set text background color in JOptionPane? Image: UIManager UI = new UIManager(); UI.put("OptionPane.background", Color.white); UIManager.put("Button.background", Color.white); UI.put("Panel.background",…
Faken143
  • 209
  • 1
  • 4
  • 10
7
votes
3 answers

How do I align text within a JTextField?

I have a JTextField with rather big bounds, the text however does not behave like I want it to. _________________ | | | | |text | | | |_________________| how would i do it so my text…
Adrian Jandl
  • 2,985
  • 4
  • 23
  • 30
7
votes
1 answer

Why JTextField.setText will fire DocumentListener's removeUpdate() before changedUpdate()?

This is my code: import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.Document; import java.awt.*; import java.awt.event.ActionEvent; import…
jocki
  • 1,728
  • 16
  • 26
7
votes
2 answers

getting integer values from textfield

I am trying to get Integer values from my jtextfield but not able to it is showing incompatible datatypes required int found string. Is there some other way of writing my code is as follows and i want to get only integer values private void…
Sumeet Gavhale
  • 800
  • 4
  • 13
  • 39
7
votes
5 answers

JButton stays pressed when focus stolen by JOptionPane

I am new to Swing and I have a situation. I am designing an application that renders the GUI components dynamically based on an xml file input(meta-data) . Now most of my JTextFields have InputVerifier set to them, for validation purpose. The input…
dareurdream
  • 241
  • 4
  • 13
7
votes
3 answers

Is there any way to get one side(i.e., right bordered line) of the jtextfield colored

Hi I prepared one swing frame in which I placed two text fields. Is there any way to get one side(i.e., right bordered line) of the jtextfield colored? Please suggest. I checked many things, but I couldn't find.Thanks in advance.
Kanth
  • 6,681
  • 3
  • 29
  • 41
7
votes
1 answer

JTextField : How to set text on the left of JTextField when text too long

I have a long String that I want to display in a JTextField. If the String is too long, it is showing the right-portion of the String, rather than the left portion, even when I use setHorizontalAlignment(JTextField.LEFT) For example, if my String is…
manhnt
  • 643
  • 1
  • 11
  • 24
6
votes
2 answers

JTextField - setColumns() method not working for me

my problem is that my JTextField -setColumns(int) "field1.setColumns(5);" ...doesn't work. I'm guessing its a layout manager problem. However, I'm learning from an exercise book. The only layouts I know are flowLayout, borderLayout and…
cworner1
  • 461
  • 4
  • 13
6
votes
2 answers

Java Swing JtextField inset

I am working with Netbeans GUI and I would like to add 3 pixels of space at the beginning of my jTextField : I have tryied with setMargin, setInset in the GUI but it doesn't change anything. I have another question, why the bottom right border is…
Vincent Roye
  • 2,751
  • 7
  • 33
  • 53
6
votes
2 answers

Document filter is not working in Java?

In text field more than 10 characters na, it has to show an error. For that i used document filter: JTextField field = (JTextField) txtFld; AbstractDocument document = (AbstractDocument) field.getDocument(); document.setDocumentFilter(new…
shree
  • 2,745
  • 7
  • 28
  • 35
6
votes
4 answers

how add a listener for jtexfield when it changing?

I have a JTextField. I want to invoke a function when the text in it is changed. How do I do that?
Mahdi_Nine
  • 14,205
  • 26
  • 82
  • 117
6
votes
3 answers

Handling editing events in a JTextField

I have a login form where a user can enter his credentials to login. I have a JLabel that serves to display the text telling the user that the user name cannot be empty. This label is display after a user click the login button when the text field…
CN1002
  • 1,115
  • 3
  • 20
  • 40
6
votes
2 answers

java unreasonable jtextfield sizing issue

I have searched all problems like this but I couldn't find the solution. public class FormPanel extends JPanel { private JLabel namelabel; private JLabel occlabel; private JTextField nametext; private JTextField occtext; private…
Vivian Maya
  • 498
  • 1
  • 4
  • 11
6
votes
1 answer

setBorder on JTextField does not work ? or does it?

The code is like this: JTextField txt = new JTextField(); txt.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.red)); However the text field is ignoring my call to setBorder. No changes whatsoever. I were to replace it with a JLabel (for…
Markus V.
  • 347
  • 2
  • 4
  • 6