Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

edit text

Posted on 2004-09-26
6
Medium Priority
?
158 Views
Last Modified: 2010-03-31
Hi experts,

I need code to right click on a label and get a popupmenu with the option "Edit". If pressed, a text field appears in place of the label and when text is entered and Enter is pressed the text on the label changes to that of the textfield and the label reappears.

thank you
0
Comment
Question by:Samooramad
  • 4
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12154466
Why not just get the return value of an input message from a JOptionPane?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12154474
String newText = JOptionPane.showInputDialog(parentFrame, "Set new text");
if (newText != null && (newText = newText.trim()).length() > 0) {
      label.setText(newText);
}      
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 12154497
label.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
            if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
                  String newText = JOptionPane.showInputDialog(parentFrame, "Set new text");
                  if (newText != null && (newText = newText.trim()).length() > 0) {
                        label.setText(newText);
                  }      

            }
      }
});
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Samooramad
ID: 12154586
sure. I'll try that CEHJ
0
 

Author Comment

by:Samooramad
ID: 12155454
it worked great! thanks

you definately deserve the points but could you answer a question:
how do you differentiate between right click and left click? also is there any way to differntiate between one click or double clicks?

thanks again!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12156259
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question