Java Text Field background text that disapears when clicked - java

As you can see in the title i dont know how to make a java text field with text in the background that disappears when you click on it.
So theres a textfield that says "username" and when u click on it the username disapears and you can type in your password. Is it possible to do this without a new class?

my suggestion is to use swingx library and use JXTextField. so you can set the text using setPrompt method.

Related

Select and mark part of text in android

i want to select some part of the text from text view using long press and drag. Basically am looking for a functionality like android pdf reader text selection. how can i implement this? after select some text i need to highlight it (color change/underline etc) .When i again visit the same page, app should show the content like i previously highlighted.
I saw the textview.setTextIsSelectable(true) option,
when i use this i can select the text, whats next? is this the proper method for this kind of task ? please help.
You should use
textView.setSelection(startIndex, endIndex);
instead

How to add a permanent text which is tappable and editable along with hint, which user can change in EditText of android?

I looked on google but didn't find what exactly i am looking for.
I want a edit text to have text or image which i can change by tapping it and selecting new text or image. Also i want hint followed by that text or image.
I tried multiple experiment and was able to add text(by changing selection location and adding text) and image(using drawable addition from android code)
For text :
edt.setText("Fixed Text");
Selection.setSelection(edt.getText(), edt.getText().length());
Image through XML:
android:drawableLeft="#drawable/ic_launcher"
But when i add text, i won't be able to add hint. In case of image hints get added. Also i want my permanent text and image to be tappable and updatable.
Any help would be really helpful. I want $ to be fixed and tappable, and want to change it to different currency. but want 52.63 to be hint and can be editable by user tap.
EDIT to give more clarity:
Example: i want to add part of the text as permanent and part as hint for example $ 52, so $ is permanent and not editable through user, he can select it through list view by tapping on $, but 52 he can change using android keyboard.
I am not quite sure about the whole part about the image being placed into the EditText as a hint, but if you wanted to create the $52.63 as a hint in the EditText, all you would have to do is:
edt.setHint("$52.63");
in your onCreate() method. I am not sure if this is what you are looking for, but this is a simple way to add a hint to a textEdit. If you wanted the hint to change when the user tapped the screen or something like that, I would look into adding a tap listener of the android component that you desire to be tapped to change the hint, and then modify the hint using the method above.

vaadin focus replaced component

I use replaceComponent(oldButton, newTextField) in button click listener, after that operation button is replaced by text field, but I have to click on it to be able to input text.
I want to click button and write text into text field without clicking on text field. How can I achieve that?
You need to request focus on the new TextField, using the AbstractField#focus() method, i.e.
replaceComponent(oldButton, newTextfield)
newTextField.focus();

How to set focus to the text after the hint in EditText?

I'm interested in you can set the focus to the text after the prompt to EditText? If no such attribute for xml layout? At the moent I still looked like this.
need
EDIT :
The fastest and working answer given Asok
I also found a similar way:
EditText.append("60"); // 60 or your text in EditText
A hint is no real text, it disappears after the user types something. Assuming the cursor would be at the end of the hint what behaviour would you expect when the user presses a button and the hint disappears?
What you can do is set a default text in the XML via
android:text="60"
or in code via
editText.setText("60");
and on focus jump to the end of the EditText via
editText.setSelection(editText.getText().length());
If I understand correctly you are looking to place the cursor behind the hint text, if this is correct then it is not possible, you'll have to remove hint and use setText instead, like so:
EditText et = (EditText)findViewById(R.id.sixtyseconds);
et.setText("60");
et.setSelection(et.getText().length());

Make a text field highlighted when tabbed to in NetBeans (Java)

I'm trying to make it so when I tab to some text fields on in my JFrame the data in the text field will be highlighted. I thought I had done this in the properties before but I am not seeing the option now. Does anyone know how to do this?
You could use a FocusListener to work out when your field has focus (tutorial here).
Decide whether you want to select the text in the field, or whether you just want to change the background color. It's not quite clear what you mean by highlight.

Categories

Resources