是否有调试事件的好方法?可以在Github上查看整个项目: https://github.com/nexxx/Database-Analyzer可以在此处找到工具栏类(从第98行开始的代码): https://github. com/nexxx/Database-Analyzer/blob/master/src/dba/gui/auxClasses/toolBars/ToolBar.java 解决方案相同的代码在某些情况下会导致问题,而在其他情况下不会导致问题,这使我怀疑您的代码可能无法在 AWT事件分配线程.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));cmbZoom.setPreferredSize(new Dimension(88, 29));cmbZoom.setEditable(true);((JTextField)cmbZoom.getEditor().getEditorComponent()).setHorizontalAlignment(JTextField.CENTER);cmbZoom.getEditor().getEditorComponent().addFocusListener( new FocusListener(){ public void focusGained(FocusEvent arg0) { System.out.println("GAINED"); } public void focusLost(FocusEvent arg0) { System.out.println("LOST"); } });I have already tried to remove all other listener on the combobox, remove the observer pattern, make the combobox protected and attach the listener on each child,...I have also tried to reimplement it like written on this post:JCombobox focusLost is not firing-why is that?Is there a good way to debug events?The whole project can be viewed on Github:https://github.com/nexxx/Database-AnalyzerThe toolbar class can be found here (code starting on line 98):https://github.com/nexxx/Database-Analyzer/blob/master/src/dba/gui/auxClasses/toolBars/ToolBar.java 解决方案 The fact that the same code causes problems in some circumstances but not others leads me to suspect your code may not be executing on the AWT event dispatch thread. 这篇关于无法触发可编辑JCombobox上的FocusListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-02 23:44