I want to update a particular image on TextArea(swing) ,when I enter a particular Alphabet on my keyboard. How?

50 Views Asked by At

I am trying to print particular images(which include some drawn symbols) on textarea when I type a particular Alphabet on my keyboard. How?

2

There are 2 best solutions below

0
On

You are asking me to do your homework, but still. I will give you only the pseudo code, you will have to write it on your own.

  1. Write a JFrame.
  2. Add a JLabel to the JFrame (using a label is easier than using a text pane, and it is impossible to use a text area).
  3. Add a Key Listener to either the JFrame or the JLabel depending on your application.
  4. In the handler write code to add a ImageIcon to the JLabel when the key you want is pressed or whatever.

Cheers!

0
On

You can't use a JTextArea since it can only display text.

You can use a JTextPane as it supports the display of Icons.

Check out: Auto Replace Smiles. It shows how to replace the two text characters :) with an Icon.