Solved

edit text

Posted on 2004-09-26
6
154 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

809 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