?
Solved

edit text

Posted on 2004-09-26
6
Medium Priority
?
157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Independent Software Vendors: 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!

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…
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…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

777 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