Is there a listener for inserting a cursor into the JTextField?
Here is my application. It is a wallet for upgrading my money when I spend or make a profit. Have a look at image hosting here http://tinypic.com/r/687bdk/8
At this point, I need to learn something from you. Is there a way to detect that the cursor has been positioned in one of the JText fields? If there is, then I could post a method that will remove everything in the other JTextField. As there should only be one JTextField with input. And it is unacceptable to have inputs in both text boxes.
source to share
Is there a way to detect that the cursor has been positioned in one of the JText fields? If there is, then I could post a method that will remove everything in the other JTextField.
As a user, I'm not too crazy about this design. I used accounting type apps before you have two columns (debit / credit) and the number can only be entered in one.
In these applications, the number is not removed by focus, it is removed if a value is entered in another field. This allows you to navigate between fields on the forum without disappearing data just due to a focus change.
To implement this type of functionality, you must add DocumentListener
a Document
text box. Then, when text is entered into the Document, a listener is called and you can clear the text from another text box.
Check out the section from the Swing tutorial on How to Write a DocumentListener for more information and examples.
source to share
You can add FocusListener
to each textbox ie
JTextField myTextField = new JTextField();
myTextField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
//when selected...
}
@Override
public void focusLost(FocusEvent e) {
//when not selected..
}
});
source to share