vaadin focus replaced component - java

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();

Related

Disabling JavaFX ComboBox input

How do I disable input on my editable Combobox? (Well, actually JFoenix JFXCombobox but it's basically the same apart from it's appearance)
setEditable(false) would disable keyboard input on the Combobox but the list would still appear
setDisabled(true) would disable whole Combobox but I want user to be able to focus Combobox so he can copy it's contents if necessery.
Why do I want it like that? In my forms user must first click edit button to be able to change stuff.
Basically, the method ComboBox.setEditable adds/removes an Editor to the ComboBox which can be retrieved via ComboBox.getEditor()
To keep the TextField (to copy from) but disable user-input, simply set the editable flag on the underlying TextField:
private ComboBox<String> myComboBox;
[...]
myComboBox.setEditable(true);
myComboBox.getEditor().setEditable(false);
EDIT:
As #jewelsea said in a comment below, you can hide the list as soon as the user requests to open it:
myComboBox.setOnShown(event -> comboBox.hide());
I think it would be "cleaner" to disable the button which opens the dropdown but unfortunately I have not yet found a way to do that.

Java Text Field background text that disapears when clicked

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.

How to enable cursor selector in GWT TextArea?

In my application I call an API to get the contents of the file as a String and use the TextArea UIWidget to display the file content to the user.
I want the user to be able to select the text in the text area in order to be able to copy and paste the contents of the file. When I hover over the TextArea in GWT, text selection is not being enabled. The getCursorPos function in the TextArea seems to be useful when modifying the textarea but not for selections
Text selection is enabled in TextArea by default. You either disabled it somewhere setEnabled(false), or you put another widget (panel) on top of your TextArea which prevents users from typing in or selecting a text.

How to add text to JText area without deleting the previous text it has? java

I have a JText area in my program contain a text, and I want to add more text to it, when a button is pressed but without deleting the text that it already has on it. for example
JTextArea Text = new JTextArea("including; ");
When a button is pressed, I have to add another text but without deleting the one it has already, like so;
Text.setText("including button1");
and when another button is pressed it should look like this
Text.setText("including; button1, button2");
What is the most effective way of doing this?
Use the append feature, like this
Text.append("button1,");
place this in the button / s and just write the name of the button

how to select a line in a Jtextarea?

I have a jtextarea that is not editable. It has some text in it. What i want is that when a user clicks in the jtextarea, (preferably single click), the entire line be highlighted, and this highlighted text be retrieved.
Each line actually has an email of the form name#emailid.com. To select the entire text would require triple clicks. I want the email to be selected in a single click. Is this possible?
Sure. Just implement you own listener and call http://java.sun.com/javase/6/docs/api/javax/swing/text/JTextComponent.html#select%28int,%20int%29 on the JTextArea.
But wouldn't a JList not rather fit your requirements?

Categories

Resources