0

I was wondering how you would have fixed text in a JTextfield that isn't editable and allows text to be appended at the beginning of the textfield text.

JTextfield (email) contains @domain.com by default for example.

You can type in blah@domain.com but cannot do blah@blah.com.

Is there some sort of text/input listener I can use alongside this component to implement this behaviour?

Any other solution's would be good as I want to force the user to use a specific email domain.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
unleashed
  • 915
  • 2
  • 16
  • 35

2 Answers2

2

Keep it simple just append constant to text obtained from text field. Also user should be informed that something is added to his input possibly by using Label.

If you want to allow several domains then use some combobox or list.

viktor
  • 1,277
  • 10
  • 16
2

I like viktor's simple solution.

However, if you want a more complex solution, then check out: Limited selection in a JTextField/JTextComponent?

It shows how to have fixed text at the beginning of the text field. I would guess you can customize it to have the fixed text at the end of the text field.

Community
  • 1
  • 1
camickr
  • 321,443
  • 19
  • 166
  • 288