Solved

edit text

Posted on 2004-09-26
6
150 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PDFBox - convert image to PDF, PDF resolution 3 70
Problem to start Neon 20 54
recursion example 16 70
maven project error 5 24
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now