private static void installComboBoxCopyAction(JComboBox<?> comboBox) {
    ComboBoxEditor editor = comboBox.getEditor();
    Component editorComponent = editor != null ? editor.getEditorComponent() : null;
    if (!(editorComponent instanceof JTextComponent)) return;
    InputMap inputMap = ((JTextComponent)editorComponent).getInputMap();
    if (inputMap != null) {
      KeyStroke[] strokes = inputMap.allKeys();
      if (strokes != null) {
        for (KeyStroke keyStroke : strokes) {
          if (DefaultEditorKit.copyAction.equals(inputMap.get(keyStroke))) {
            comboBox.getInputMap().put(keyStroke, DefaultEditorKit.copyAction);
          }
        }
      }
    }
    comboBox.getActionMap().put(DefaultEditorKit.copyAction, new AbstractAction() {
      @Override
      public void actionPerformed(ActionEvent e) {
        if (!(e.getSource() instanceof JComboBox)) return;
        @SuppressWarnings("unchecked") JComboBox<Object> comboBox = (JComboBox<Object>)e.getSource();
        String text;
        Object selectedItem = comboBox.getSelectedItem();
        if (selectedItem instanceof String) {
          text = (String)selectedItem;
        }
        else {
          Component component = comboBox.getRenderer().getListCellRendererComponent(new JList<>(), selectedItem, 0, false, false);
          if (component instanceof JLabel) {
            text = ((JLabel)component).getText();
          }
          else if (component != null) {
            String str = component.toString();
            // skip default Component.toString and handle SimpleColoredComponent case
            text = str == null || str.startsWith(component.getClass().getName() + '[') ? null : str;
          }
          else {
            text = null;
          }
        }
        if (text != null) {
          JTextField textField = new JTextField(text);
          textField.selectAll();
          textField.copy();
        }
      }
    });
  }
private static void installComboBoxCopyAction(JComboBox<?> comboBox)