• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mouse and Key Listeners don't work on JPanel

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to use mouse listeners and key listeners in A Jpanel because i use it to edit a JPG. To allow listeners I use:

jWriteOnImage extends JPanel. The strange thing is that in a JFrame everything works perfectly, but the listeners don't work if the JPanel is in a JDialog.

Thanks for your help,

Alejandro Barrero
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To get better help sooner, post a SSCCE that clearly demonstrates your problem.

And do you think you could indent your code with smaller/less indents? The snippet you posted is almost out of sight.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Craig, but I don't think you are addressing my problem; I am afraid I did not explained clearly. What I am doing is adding listeners to the JPanel to react to events when the user clicks on the panel to select a position to type and when the user types a key to enter data into the JPane. My code works when the JPanel is in a JFrame (the user can enter text in different places and then can save the image with the text entries); the mouse listeners and key listeners do the work. My problem is that if I change the JFrame to a JDialog my code doesn't work.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So it seems that your problem only occurs in specified situations, situations that we won't be able to reproduce without seeing your code I'll bet. My recommendation goes back to Darryl's: please post an SSCCE. You'll find a helpful link on how to create this creature and why it's important in Darryl's post again.

For instance, this is my SSCCE of your problem. Note that it's a bit too long for a true SSCCE, sorry. Also, to change the JTextField to a JLabel, you must press enter after entering text:

[ June 22, 2008: Message edited by: pete stein ]
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Pete; I enjoyed studying your code. My code also works when it is in a JFrame. Here are the two classes the I use:
The JPanel

The JDialog:
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you run mine, you'll see that it works the same for a JFrame as for a JDialog. Unfortunately I can't run yours as you are missing the TextDialog class code.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the class Pete:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic