Mouse and Key Listeners don't work on JPanel
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
Your help will be greatly appreciated,
Alejandro Barrero
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
And do you think you could indent your code with smaller/less indents? The snippet you posted is almost out of sight.
luck, db
There are no new questions, but there may be new answers.
Alejandro Barrero
Ranch Hand
Posts: 502
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
Your help will be greatly appreciated,
Alejandro Barrero
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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 ]
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
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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:
The JPanel
The JDialog:
Your help will be greatly appreciated,
Alejandro Barrero
pete stein
Bartender
Posts: 1561
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Here is the class Pete:
Your help will be greatly appreciated,
Alejandro Barrero
| Story like this gets better after being told a few times. Or maybe it's just a tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |







