Making a editable form in java netbeans - java

How can I design a editable form as in detail of a person by clicking edit button and edit the respective fields of person's details and save it on the same place where they are shown.
eg.
Full Name : JTextField1
Address: JTextField2
and so on...
Now What I want is to save those values on respective places and when I want to edit them then show editable textfield with same values displayed.
Are there any API's or plugins to do it or should I just have to do as setVisible(true/false) for necessary action to perform??

If you are using JavaFX, you can use setEditable(boolean), which will disable or enable the field for editing. You can also use setDisabled(boolean) to disable the field for anything other than viewing.
If you are using Swing/AWT, you can use setEditable(boolean) as well as setEnabled(boolean) to do the same as JavaFX.
Since you are using Swing/Awt, use setEditable to disable or enable the fields when you press the Edit button. :)

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.

GWT- PopupPanel with search?

I am looking for a way to create a popup dialog box when a user double clicks a textinput field that will contain a scroll-able list (from database table) where the user can select a field, hit ok, and have it placed into the textbox when popup closes.
The other major requirement is to have a filter/ or search field in the popup to aid the user in finding the correct option to select from quicker.
What is the best way to implement this?
Modification to gwt's popup panel? maybe a JOptionPane? are there any simple solutions already designed for free commercial use?
You could implement this with a com.google.gwt.user.client.ui.PopupPanel. You can make a PopupPanel that contains a ListBox with your data from the database, along with a OK button. When a user selects a value and hits OK, you should utilize an EventBus along with a custom Event that will pass the value to the field on the page. The page will have an event handler that will catch the event and put it into the field.
Another option is to use a com.google.gwt.user.client.ui.SuggestBox. It is a box that autocompletes / suggests values as you type, kind of like the Youtube search bar.
I can offer more resources to help you accomplish this, if you'd like.

Saving user settings from GUI

I am currently coding an application, which has an option frame JDialog. This frame contains various checkboxes and text fields that the user can configure.
I want to save the changes the user made to the options.
What is the best way of doing so?
My first thought was implementing it by saving it in a file with the format of e.g.
checkBox1=value;
textArea1="value";
By using the following I could get the field, but I would need to do something like (for the checkbox) myField.isSelected(); which does not work.
Field myField = MyClass.class.getDeclaredField(name);
Thank you in advance.
You can use java.util.prefs.Preferences to store the configuration in your JDialog. This question - Java Preference Manager - discuss about how to create frontend+backend solution by using Preferences (something like JFace org.eclipse.jface.preference)

AutoCompleteDecorate implemented on JComboBox

For those who are familiar with SwingX's AutoCompleteDecorator, I have a question regarding handling of JComboBox's Popup Visibility. I used AutoCompleteDecorate.decorate(JComboBox combobox) in my current project which I already mentioned in my previous posts, the problem I encountered is when ever the user type a keyword that doesn't match any of the combobox items, the popup remains visible. For the convenience of the users, I would like to hide combobox's popup if the keyword typed doesn't match any of combobox items.
If you want the autocompletion feature, but you don't want to have a popup in the way (especially, as you mention, when entered text doesn't match any item) you might like to try the opensource JIDE Common Layer. It has a very useful (I use it a lot myself) autocompletion feature that you can apply to JComboBoxes, JTextFields, etc..
You can see a Java Web Start overview of the components by clicking on the "RUN IT" link on the above page, or by clicking here. Navigate to
Demos->AutoCompletion Demo->AutoCompletion combo box and text field->AutoCompletion JTextField with a hidden data
to try it out. You can also see the source code by clicking on Browse Source Code.
You can enable/disable a strict flag in order to prevent/allow user to enter text not matched with items.
However, as far as I have tested, JIDE's combo boxes with autocompletion also have the "issue" that keep their popup open even if no match is found, but what I'm suggesting here is to try an autocompleting textfield which has no popup at all (they autocomplete in place, highlighting the part of the matched text that you didn't manually type-in).

Is it possible to disable a JComboBox when a JTextField is edited?

I'm working on a form and I'd like to have a drop-down box where you select a person. It brings up their stored information in the text-fields below, but as soon as you edit one of the text-fields it disables the drop-down box until you save or cancel the changes. The purpose of this is to prevent the user from editing something, thinking it's saved, and then changing to a different person and losing their changes.
Add a DocumentListener to all your text fields. Whenever any data is changed you disable the combo box. When the data is saved you enable the combo box.
See How to Write a DocumentListener for more information and examples.
A better approach might be to popup a JDialog with the data to be changed.
Dynamically disabling combo boxes doesn't seem like a common practice. Perhaps instead you could indicate to the user when something is saved, and if the user attempts to switch people after info has been inputted, you could notify them and ask if they want to continue and lose the data. Is it not possible that some users will enter data, try to use a disabled combo box, and not knowing why it is disabled, they will think you program is broken?

Categories

Resources