JComponent () { if (myNameField.getText().trim().isEmpty()) { return myNameField; } for (TaskDialogPanel panel : myPanels) { final JComponent component = panel.getPreferredFocusedComponent(); if (component != null) { return component; } } if (myTaskStateCombo.isVisible() && myTaskStateCombo.isEnabled()){ return myTaskStateCombo.getComboBox(); } return null; }