0

I want a textfield which looks like this :

textfield . textfield . textfield. textfield

and to enter just numbers in the textfields. Can you help me, please? :)

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

1

You don't need a parent textfield to act as a container for 4 textfields. Place 4 textfields inside a panel.

The steps to achieve this in java swing:
1.Create a JPanel with a white background.
2.Add 4 JTextFields seperated by JLabel with value .(Use the GridLayout to keep them in a single row).
3.Disable the highlighting of JTextFields and its border or make the textfield transparent
4.Instead add a border to the JPanel when any of the JTextfields accepts input.

Community
  • 1
  • 1
Sorter
  • 9,704
  • 6
  • 64
  • 74
  • Thank you, it works :) now I am trying to put a restriction to enter just numbers between 0 and 255 in the textfield. –  Mar 07 '13 at 13:31
  • @user2044918: Look for `InputVerifier` or `DocumetnListener`. – Catalina Island Mar 07 '13 at 15:15
  • and is there any possibility not to let me type incorrect values(letters) instead of returning an exception if i type a letter? –  Mar 08 '13 at 11:29
  • you can use `KeyListener` and check the typed key and discard all unwanted letters and please click the tick on the answer if it answered your question. – Sorter Mar 08 '13 at 12:04