79247196

Date: 2024-12-03 10:31:53
Score: 0.5
Natty:
Report link

Thank you Abra for your requests. It made me rethink the problem. And here is the solution.

public void mousePressed(MouseEvent e)
  {
     DataButton jButton = (DataButton) e.getComponent();
     String caption = jButton.getData();

     JTextComponent focusElement = findFocusElement();
     if (focusElement != null)
     {
        int position = focusElement.getCaretPosition();
        String text = focusElement.getText();
        String before = text.substring(0, position);
        String after = text.substring(position);
        focusElement.setText(before + caption + after);
        focusElement.requestFocus();
        focusElement.setCaretPosition(position + 1);
     }
  }
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: dragoness