?
Solved

Dectecting edit

Posted on 2005-04-03
9
Medium Priority
?
201 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
[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
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

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

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…
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.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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