focuslistener

Detecting JTextField “deselect” event

大城市里の小女人 提交于 2020-02-09 04:41:41
问题 Is there some way to detect if a JTextField is deselected, i.e. the field WAS selected but now you have selected something else. The reason why I want to do this is because I want to check my users forms for any illegal characters before they try to submit their data. If there is some easier way to do that, instead of the way I'm trying to solve it, I'll gladly accept enlightenment. 回答1: At first though use a FocusAdapter and override focusLost(FocusEvent fe) which will be called when

FocusListener on editable JCombobox not firing

心不动则不痛 提交于 2019-12-20 03:46:40
问题 First of all: Sorry that I cannot provide a SSCCE. I tried to recreate this problem on a small project, but without success, or should I say with success, because its working there! So here is my Problem: I have an editable JCombobox, which should listen to a focus event by clicking in the editor component. But it doesn´t. Here is a code snippet where I attach the listener: cmbZoom.setToolTipText(locale.getString("GUI_ZoomFactor")); cmbZoom.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 16));

java restrict switching of window/Jpanel

萝らか妹 提交于 2019-12-11 10:17:23
问题 I have JFrame with 3 JPanel (basically three tabs). one of the panel has a textbox. there is value restriction on textbox. it means, user can enter only 1-1000 number in it. If he enters number >1000, it throws the warning message. Now I am using focuslistener to save the entered number as soon as it looses the focus. But if the user enters 1200 and click on another tab(panel), it gives me expected warning message but also goes to the another tab. I need to remain in same panel if there is

Make JSpinner Select Text When Focused

白昼怎懂夜的黑 提交于 2019-12-04 00:59:43
问题 I would like to change the behavior of a JSpinner so that when you click on the text, it selects it. This makes it easier to replace the field with the value that you want. Unfortunately, I can't get the behavior to work and instead, it just inserts the cursor in the text without selecting what is already there. I have tried adding a focus Listener to both the JSpinner itself and the text area itself, via ((DefaultEditor) this.getEditor()).getTextField() , yet neither of these seem to have

Make JSpinner Select Text When Focused

99封情书 提交于 2019-12-01 03:40:59
I would like to change the behavior of a JSpinner so that when you click on the text, it selects it. This makes it easier to replace the field with the value that you want. Unfortunately, I can't get the behavior to work and instead, it just inserts the cursor in the text without selecting what is already there. I have tried adding a focus Listener to both the JSpinner itself and the text area itself, via ((DefaultEditor) this.getEditor()).getTextField() , yet neither of these seem to have the intended effect. My code (for the JSpinner itself) is as follows: spinner.addFocusListener(new

JCombobox focusLost is not firing-why is that?

老子叫甜甜 提交于 2019-11-28 12:13:50
I have a JCombobox in my code. I have added the FocusLost event . But it didn't fired anyway. I have tried lots of time but didn't find solution. jcbItemType.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { jcbItemTypeFocusLost(evt); } }); private void jcbItemTypeFocusLost(java.awt.event.FocusEvent evt) { // TODO add your handling code here: System.out.println("name=" + ((Component) evt.getSource()).getName()); System.out.println("index=" + jcbItemType.getSelectedIndex()); } But nothing is printed in console. Please suggest me what I

JCombobox focusLost is not firing-why is that?

℡╲_俬逩灬. 提交于 2019-11-27 06:49:21
问题 I have a JCombobox in my code. I have added the FocusLost event . But it didn't fired anyway. I have tried lots of time but didn't find solution. jcbItemType.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { jcbItemTypeFocusLost(evt); } }); private void jcbItemTypeFocusLost(java.awt.event.FocusEvent evt) { // TODO add your handling code here: System.out.println("name=" + ((Component) evt.getSource()).getName()); System.out.println(

Detecting JTextField “deselect” event

谁说我不能喝 提交于 2019-11-27 02:07:15
Is there some way to detect if a JTextField is deselected, i.e. the field WAS selected but now you have selected something else. The reason why I want to do this is because I want to check my users forms for any illegal characters before they try to submit their data. If there is some easier way to do that, instead of the way I'm trying to solve it, I'll gladly accept enlightenment. David Kroukamp At first though use a FocusAdapter and override focusLost(FocusEvent fe) which will be called when JTextField loses focuses, i.e another component is selected. However because you have a purpose: I