Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Dectecting edit

Posted on 2005-04-03
9
Medium Priority
?
203 Views
Last Modified: 2010-03-31
Hi,
Before doing the update of my GUI, i would like to check whether the user has dedited data on that component, If no then, no need to do update, and just do update where the component has
been edited since last populated.
How do i check for that?
0
Comment
Question by:komlaaa
  • 5
  • 3
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13695294
you need to handle that yourself, for example if using a textfield you could remeber the value it was originally set to (by your apop) and then compare that to the value later.
0
 
LVL 92

Expert Comment

by:objects
ID: 13695302
You could also use a listener to listen for user edits and set a flag when the user made a change (though this would miss the case when a user made a change, and then changed it back to what it already was previously)
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 13695464
Actually, the listener could still work, the person would just have to incorparate the undo logic into the program.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:komlaaa
ID: 13695618
What type of listener then
0
 
LVL 92

Expert Comment

by:objects
ID: 13695630
depends on the component, for a text field use a DocumentListener
0
 

Author Comment

by:komlaaa
ID: 13700401
below is the code from:
http://www.javaalmanac.com/egs/javax.swing.text/ChangeEvt.html
But i am not sure how to use it to before do update on my JTextFields:
I baiscally want to pop up JOptionPane asking the user if he want to save the changes?
something like If( .....Not sure what to put here) then ( ... I know what i should do here...)
e1016. Listening for Editing Changes in a JTextComponent
A DocumentEvent is fired each time characters are inserted or removed from a text component. The event is also fired if the set of attributes in the text component is changed.
    JTextComponent textcomp = new JTextPane();
    textcomp.setText("Initial Text");
    textcomp.getDocument().addDocumentListener(new DocumentListener() {
        // This method is called after an insert into the document
        public void insertUpdate(DocumentEvent evt) {
            // Get index of newly inserted characters
            int off = evt.getOffset();
   
            // Get length of new inserted characters
            int len = evt.getLength();
   
            try {
                // Get inserted string
                String str = evt.getDocument().getText(off, len);
            } catch (BadLocationException e) {
            }
        }
   
        // This method is called after a removal from the document
        public void removeUpdate(DocumentEvent evt) {
            // Get starting index of removed characters
            int off = evt.getOffset();
   
            // Get length of removed characters
            int len = evt.getLength();
   
            // The removed characters are not available
        }
   
        // This method is called after one or more attributes have changed.
        // This method is not called when characters are inserted with attributes.
        public void changedUpdate(DocumentEvent evt) {
            // Get starting index of characters whose attributes have changed
            int off = evt.getOffset();
   
            // Get length of characters whose attributes have changed
            int len = evt.getLength();
        }
    });

0
 
LVL 92

Expert Comment

by:objects
ID: 13702019
The DocumentListener would only be used to flaf when an update has been made, prompting the user would need to be done elsewhere at the point where it needs to be saved.
0
 

Author Comment

by:komlaaa
ID: 13728595
>The DocumentListener would only be used to flaf when an update has been made, >prompting the user would need to be done elsewhere at the point where it needs to be >saved.
Do u have a similar example? I mena in a sample program.
0
 
LVL 92

Accepted Solution

by:
objects earned 1600 total points
ID: 13731064
Heres background on DocumentListener

http://java.sun.com/docs/books/tutorial/uiswing/events/documentlistener.html

All your listener would need to do is set a flag when the doc changed.
Then test that flag when it is time to save.

Though just saving the original value when you initially set the field should be sufficient.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

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…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

564 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