void (JLabel textComponent, JComponent component) { textComponent.setLabelFor(component); if (component instanceof JTextField) { ((JTextField)component).getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { validateData(); } @Override public void removeUpdate(DocumentEvent e) { validateData(); } @Override public void changedUpdate(DocumentEvent e) { validateData(); } }); } else if (component instanceof JComboBox jComboBox) { jComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { validateData(); } }); if (jComboBox.isEditable()) { jComboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { validateData(); } }); } } }