The use case in my UI is to populate two JTextField
components based on double clicking items in a JList
. The easy was is to use a JCheckBox
As everyone has suggested initialize a FocusListener to both the text fields and and point it to a string variable when either of the loses focus.
Code:
String LastFocusLost = null;
jTextField1.addFocusListener(new java.awt.event.FocusAdapter()
{
public void focusLost(java.awt.event.FocusEvent evt)
{
LastFocusLost = "jTextField1";
}
});
jTextField2.addFocusListener(new java.awt.event.FocusAdapter()
{
public void focusLost(java.awt.event.FocusEvent evt)
{
LastFocusLost = "jTextField2";
}
});
In the mouseListener add a if-else then:
if ("jTextField1".equals(LastFocusLost))
{
//;
}
else if ("jTextField2".equals(LastFocusLost))
{
//;
}