Page 1 of 2 12 LastLast
Results 1 to 20 of 22
Like Tree6Likes

Thread: Storing previous errors and displaying

  1. #1
    shivam0101 is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default Storing previous errors and displaying

    I am trying to display errors after file validation in jtextarea. I am validating only those part which are visible in viewport. But i want to show all the errors in the file, so, i am storing it in a temp variable and showing. Whenever i scroll to the next set of lines in the viewport, those errors in the previous set lines which were in the viewport are disappearing. Can someone tell me how to solve this?

    errorList.clear(); // i used this to clear the previous errors. So when there is any corrections are made that error will not be shown.

    This i have posted in stackoverflow.com, i did not get solution for it.
    http://stackoverflow.com/questions/9...and-displaying


    Java Code:
    private void displayErrors(){
      errorTextArea.setText(null);                
            try{
                if(prevErrors.size() > 0){
                    for(int i=0; i<prevErrors.size(); i++){
                        if(!errorList.contains(prevErrors.get(i))){
                            errorList.add(prevErrors.get(i));
                        }
                    }
    
                }
            }catch(Exception e){
                System.out.println(e);
            }
    
            try {
                for (int i = 0; i < errorList.size(); i++) {
                    errorTextArea.append(errorList.get(i) + "\n");
                }
                //errorList.clear();
                errorTextArea.setCaretPosition(0);                    
    
            } catch (Exception ex) {
                System.out.println(ex);
            }
    
            try{                    
                prevErrors.addAll(errorList);
            }catch(Exception e){
                System.out.println(e);
            }                
        }
      }
    Last edited by shivam0101; 03-12-2012 at 06:52 PM. Reason: Corrected the code, removed unwanted lines

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Storing previous errors and displaying

    Quote Originally Posted by shivam0101 View Post
    Java Code:
    function displayErrors(){
    I don't know what that is, but it's certainly not Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Storing previous errors and displaying

    Looks like the definition of a method that returns a function object.

  4. #4
    shivam0101 is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default Re: Storing previous errors and displaying

    I have corrected the code, please look once again

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Storing previous errors and displaying

    Can you make a small, complete program that compiles, executes and shows the problem?
    DarrylBurke likes this.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Storing previous errors and displaying

    Quote Originally Posted by Norm View Post
    Looks like the definition of a method that returns a function object.
    And where's the return statement, huh? ;)
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Storing previous errors and displaying

    That would be an error!

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Storing previous errors and displaying

    He possibly didn't get an answer at stackoverflow because hovercraft doesn't know what he's doing, or else because the question doesn't provide enough information to be truly answerable. If someone can answer it here (come on Darryl and/or Norm), then it's the former, and if not, the latter.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Storing previous errors and displaying

    Need a SSCCE to test with.
    DarrylBurke likes this.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Storing previous errors and displaying

    Quote Originally Posted by Norm View Post
    Need a SSCCE to test with.
    Yup

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    shivam0101 is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default Re: Storing previous errors and displaying

    Thanks for your replies, i have made a very simple application which produces the same output. http://www.filedropper.com/sampleapplication You can download and run and see

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Storing previous errors and displaying

    Please post the code in the forum so we can see it. No links or rar files.
    Be sure to wrap the code in code tags
    DarrylBurke likes this.

  13. #13
    shivam0101 is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default Re: Storing previous errors and displaying

    Java Code:
    package sampleapplication;
    
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.util.ArrayList;
    import java.util.List;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.JTextComponent;
    import javax.swing.text.Utilities;
    
    
    public class SampleEditor extends javax.swing.JFrame {
        private List prevErrors = new ArrayList();
    
        /** Creates new form SampleEditor */
        public SampleEditor() {
            initComponents();
             
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
        private void initComponents() {
    
            jScrollPane1 = new javax.swing.JScrollPane();
            editorTextArea = new javax.swing.JTextArea();
            jScrollPane2 = new javax.swing.JScrollPane();
            errorTextArea = new javax.swing.JTextArea();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            editorTextArea.setColumns(20);
            editorTextArea.setRows(5);
            editorTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    editorTextAreaKeyReleased(evt);
                }
            });
            jScrollPane1.setViewportView(editorTextArea);
    
            errorTextArea.setColumns(20);
            errorTextArea.setRows(5);
            jScrollPane2.setViewportView(errorTextArea);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>//GEN-END:initComponents
    
       
        private void validation() {
            String delimiter = "\n";
            int lineNo = 0;
            int startLine = 0;
            int endLine = 0;
                    
            String text = editorTextArea.getText();
            String[] lines = text.split(delimiter);
            List errors = new ArrayList(); 
            String line;
            String valString1;
            String valString2;
            String valString3;
            String valString4;
            
            try {
                Rectangle r = editorTextArea.getVisibleRect();
                Point topLeft = new Point(r.x, r.y);
                Point bottomRight = new Point(r.x + r.width, r.y + r.height);
    
                startLine = getRow(topLeft, editorTextArea) - 1;
                endLine = getRow(bottomRight, editorTextArea);
            } catch (Exception ex) {
                System.out.println(ex);
            }
        
            try {
                for (int i = startLine; i <= endLine; i++) {
                    lineNo++;
                    line = lines[i];
                    
                    valString1 = line.substring(0, 3);
                    valString2 = line.substring(4, 7);
                    valString3 = line.substring(8, 11);
                    valString4 = line.substring(13, 15);
    
                    if (!valString1.equals("ABC")) {
                        errors.add("Line No" + lineNo + " Invalid chars 0, 3");
                    }
    
                    if (!valString2.equals("EFG")) {
                        errors.add("Line No" + lineNo + " Invalid chars 4, 7");
                    }
    
                    if (!valString3.equals("IJK")) {
                        errors.add("Line No" + lineNo + " Invalid chars 8, 11");
                    }
    
                    if (!valString4.equals("NO")) {
                        errors.add("Line No" + lineNo + " Invalid chars 13, 15");
                    }
                }
            } catch (Exception e) {
                //System.out.println(e);
            } 
            displayErrors(errors);
        } 
        
        
        public int getViewToModelPos(Point p, JTextComponent editor){
             int pos = 0;
             try{
                pos = editor.viewToModel(p);
             }catch(Exception ex){
                 
             }
             return pos;
        }
        
        
        public int getRow(Point point, JTextComponent editor) {
            int pos = getViewToModelPos(point, editor);
            int rn = (pos == 0) ? 1 : 0;
            try {
                int offs = pos;
                while (offs > 0) {
                    offs = Utilities.getRowStart(editor, offs) - 1;
                    rn++;
                }
            } catch (BadLocationException e) {
                System.out.println(e);
            }
            return rn;
        }
        
        
        private void displayErrors(List errors) {
            errorTextArea.setText(null);
            String errorStr;      
            
            try {
                for (int i = 0; i < errors.size(); i++) {                
                    errorTextArea.append(errors.get(i) + "\n");
                }
            } catch (Exception ex) {
                System.out.println(ex);
            }
        }    
        
    private void editorTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_editorTextAreaKeyReleased
        validation();
    }//GEN-LAST:event_editorTextAreaKeyReleased
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(SampleEditor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(SampleEditor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(SampleEditor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(SampleEditor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new SampleEditor().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JTextArea editorTextArea;
        private javax.swing.JTextArea errorTextArea;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        // End of variables declaration//GEN-END:variables
    
    }

  14. #14
    shivam0101 is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default Re: Storing previous errors and displaying

    readme.txt
    import the source to netbeans and run. Do not maximize the window, only 6 - 7 lines should appear in the viewport, so that you can scroll.

    open sample.txt, copy and paste the content into the editor

    change the firstline in the editor from,

    ABCDEFGHIJKLMNOPQRSTUVWXYZ

    to

    AECDEFGHIJKLMNOPQRSTUVWXYZ


    Scrolldown to the last line and change from

    ABCDEFGHIJKLMNOPQRSTUVWXYZ

    to

    AECDEFGHIJKLMNOPQRSTUVWXYZ


    You can observe the previous error disappear and the recent error will appear

  15. #15
    shivam0101 is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default Re: Storing previous errors and displaying

    sample.txt
    ABCDEFGHIJKLMNOPQRS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    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    ABCDEFGHIJKLMNOPQRSTUVWXYZ

  16. #16
    shivam0101 is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default Re: Storing previous errors and displaying

    I think, that information is enough

  17. #17
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Storing previous errors and displaying

    How do you execute the code to see the problem? What problem does this code show?
    I get two empty text areas displayed.
    Now what?

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Storing previous errors and displaying

    Can you make a completely self contained testing program that does not require anything for testing other than a compiler and the java.exe program?

    With minimal user intervention.
    DarrylBurke likes this.

  19. #19
    shivam0101 is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default Re: Storing previous errors and displaying

    I think i have given all the instructions. in the posts.

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Storing previous errors and displaying

    Your instructions require too many manual steps. Can you preload everything into the textarea so the user only has to do a mouse click or press a Button to see the problem.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  2. Error filterStart, startup failed due to previous errors
    By Prakash2345 in forum Web Frameworks
    Replies: 0
    Last Post: 01-29-2010, 09:45 AM
  3. Replies: 3
    Last Post: 10-28-2009, 01:45 AM
  4. Replies: 3
    Last Post: 03-08-2009, 01:51 AM
  5. Next and Previous Buttons
    By JavaNewb in forum New To Java
    Replies: 1
    Last Post: 05-09-2008, 01:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •