0

I want a reliable way to get the entered text by the user as a String for further use. I do not want to use a spefcific input text field though. Using the normal KeyListener() would problably be a possibility but that is not what I want. A text input field would be unsuitable for my usecase.

I do not have any code examples, because I dont have any idea, how to taccle the problem. I do not want to use the KeyListener because it does not provide a reliable way to see wether the user has stopped writing. And each key has to be programmed on its own or is it just my way of using the listener inpropally?

public void keyPressed(KeyEvent e) {
    if (code == KeyEvent.VK_W){
        upPressed = true;
    }
}
public void keyReleased(KeyEvent e) {
    if (code == KeyEvent.VK_W){
        upPressed = false;
    }
}

and the text input fields can not be styled (if they can, I do not know how!)

  • Hello. Could you provide your reasoning behind not wanting to use textfield nor keylisteners. For now your question looks like [XY problem](https://meta.stackexchange.com/q/66377) - which may not have simple solution since you rejected them. – Pshemo Feb 20 '23 at 18:16
  • Please use [edit] option to clarify your question. – Pshemo Feb 20 '23 at 18:17
  • Sorry but I still am not sure how not being able to style textfield prevents you from using it to read data from user. Anyway maybe this will help [How to change text color in the JTextArea?](https://stackoverflow.com/q/9650992) – Pshemo Feb 20 '23 at 19:12
  • @Pshemo is there any way to make the backgrount of the input field transparent? – Chromatischer Feb 20 '23 at 19:51
  • 1
    Based on [Making a JTextField background transparent](https://stackoverflow.com/q/22700216) it looks like all you need is `yourJTextField.setOpaque(false);` – Pshemo Feb 20 '23 at 20:19
  • For more alternatives like [How to have a transparent JTextField?](https://stackoverflow.com/q/63417528) consider googling using query like `java swing jtextfield transparent background site:stackoverflow.com`. The `site:stackoverflow.com` part will limit all results to this site (`stackoverflow.com`) – Pshemo Feb 20 '23 at 20:30

0 Answers0