Un-editing / removing focus from a Vaadin TextField - java

Does anyone know how to cancel the editing state of a Vaadin TextField that's inside a Table? My concrete use case is that I have a table with multiple TextFields in it, that show different values when they are edited as opposed to viewed. The user clicks on a TextField, this makes the field display its editable content. If the user changes his mind and wants to stop editing the field (by pressing ESC) the field should cancel any changes the user might have made to its content and revert to displaying its view value.
So far I've been able to move the focus to another TextField but this is not what I ultimately want to achieve. Moving the focus to the parent Table would be acceptable, but doing so programmatically by calling table.focus() does not produce any visible results.
Thanks for your help,
Radu

To revert the value of any field - including TextField - before it gets committed, AbstractField#discard()

Related

JavaFX requestFocus() deletes contents of TextField when opening with spacebar

I'm running into an issue with the requestFocus() method. Whenever I click on a link from a VBox table in my application, a details menu drops down indicating username etc which are editable. The problem is, when I open the link in the VBox using the spacebar, JavaFX puts a focus on the TextField, but highlights it. By the time I release the spacebar, the highlighted text is deleted.
Basically, when the TextField is given focus using a spacebar, the entire contents are highlighted and replaced with a space character. Pushing enter to open the link still highlights the text, but doesn't do anything else since it doesn't add any characters.
How do I make sure the text inside a TextField doesn't get highlighted?
Thanks.
The solution for TextField (entire content) doesn't get highlighted is adding the .selectedEnd() after the .requestFocus()
textField.requestFocus();
textField.selectEnd();
However, i'm not really sure for your case that deal with spacebar. Hope this help.

In ADF Page refresh

I have three tables in a page. When I click on a button, I update only one of the tables. But since I use request scope on button event, the page reloads fully and updated value gets lost. Can you suggest a solution, so that my data will be displayed after button event.
Have you tried to set partialSubmit="true" in your button? If you set this attribute, you must set in each table a PartialTriggers to the button.
I hope help you.
Marcos.
The data has to be in the viewScope/pageFlowScope depending on whether its in a bounded taskFlow or not.
And in your button event you need to update the data in the viewScope/pageFlowScope and then bind your tables with those data.
All the event handlers can be in backingBean scope and not necessarily be in requestScope.

Check for entry in text fields and comboboxes to enable a button Java Desktop Application

I am writing a Java application for digitizing a group of documents in the office that I am working in and I am wanting to check if 5 textfields are populated and 4 combobox fields as well before the save button is enabled (I have it checking if i press a button (that happily says "Check"), but i would much rather have it auto-check to see if they are populated or if they are null).
If it makes a difference i am using NetBeans for this project.
Basically I need the fields to have something in them before the document can be saved.
Any and all help will be greatly appreciated as this is the final step in creating this application... :D
Thanks,
Erik
There are two ways (I can think of):
1- Put a listener on each field, this listener will be triggered when the field is populated. Inside the listener increment a counter for example, or set a flag. If all flags are set or if the counter reaches (9 in your example) then enable the button.
2- Enable the Save button, but call a validate() method before doing the Save action. Any unpopulated field will have a red mark beside it (shown by validating) like in web applications.

JTable custom cell renderer focus problem

I have a table like this. The second column uses a JTextField renderer and the third column uses a JPasswordField based renderer and editor.
Looks good. But the problem is We have to type the values and must hit "ENTER". In that image, I have typed my password but didn't hit Enter. So If I click the 'Save & Close' button, it'll show me an error that password field is empty.
Previously I have used only JTextFields and JPasswordFields under JTabbedPane and it worked well. When I had to add more and more stuff, I changed it to a table like this.
For now I have put a label to let people know that they should hit the ENTER.. This is not nice. Another big issue. Atleast in Nimbus Look and feel, we get an idea that that field is still in focus. In Windows system look, there's not much visible difference whether the field is focused or not.
I need the Username field or password field to set it's value when I click 'Save & Close' button. Please help me.
So your problem is, that you are still editing the cell. So you have to stop the editing and then the cell will be changed.
At your button you can get the cell who is being edited with
TableCellEditor cellEditor = table.getCellEditor();
then you can stop the editing with
if(cellEditor!=null){
cellEditor.stopCellEditing();
}
and then you can save the value
Tell the table to automatically commit when losing focus:
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

How to Mirror Edits across a Table Cell and Text Field

The desired behavior is akin to the mirrored text editing field provided in Excel when a given cell is selected, allowing more space to view the contents of the cell. I have a JTable with 5 columns and n rows. Column 2 holds expressions that can be arbitrarily long, thus I'd like to provide a separate JTextField to work with for editing the contents of the expression cell per row. The other fields are directly editable in the table. When the user clicks on a field in column 2, however, I want to send them to the text field. Any contents preexisting in the cell should be appear in the text field and additional edits in the text field should be mirrored in the table cell. Likewise, if someone double-clicks on the cell and edits it directly, I want those changes reflected in the text field. Thus, the user can choose to edit in either space and both are updated. Ideally, they are updated per keystroke, but update upon hitting return is acceptable.
So, far I've got the JTable, TableModel, TableModelListener, JTextField, ListSelectionListener, and AbstractAction, working together to provide most of the functionality described above. I'm missing the reflection of direct table cell edits to the text field and per-keystoke updates.
Are their ideas on how best to construct this behavior?
Well, if you want to get data from the table to the cell then you add the code to your TableModel's setValueAt() function, which should run when the user changes the content in an editable cell. I don't think that will update per-keystroke though.
If you want to move data from the textbox to the table cell use code like this
myJTextField.getDocument().addDocumentListener(new MyDocumentListener());
Where MyDocumentListener is an implementation of the javax.swing.event.DocumentListener interface
That will get you per-keystroke updates from the box to the table. But for the other way around it's a bit trickier.
There are two ways you might be able to go about doing it
1) Add a key listener to the table, and when the user starts typing check to see what table element is active, and intercept keystrokes as they type. That's kind of messy, though.
2) Another option might be to try to grab or replace the component that the table is using to actually let the user make the changes. I think that JTable actually allows you to change the editor component if you dig around.

Categories