Solved

edit text

Posted on 2004-09-26
6
155 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

733 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