Results 1 to 5 of 5
  1. #1
    bulldo is offline Member
    Join Date
    Jul 2010
    Posts
    8
    Rep Power
    0

    Default load a text in a view

    Hi all
    I've added a view to my plugin and in this view I created a text zone .
    What I want to do now is to display the content of a file in my text zone . I used a clasic methode : parsing a file and print the content but I have a problem in my code because I didn't manage to have an exact copy of my file : I got the content in only one line !! there is no wrap
    here is the code :

    Java Code:
    public void createPartControl(Composite parent) {
    	text = new Text (parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    
    	try {
    		FileInputStream myFile = new FileInputStream("......");
    		DataInputStream myInput = new DataInputStream (myFile);
    		BufferedReader br = new BufferedReader(new InputStreamReader(myInput));
    		String line ;
    		StringBuilder builder  = new StringBuilder();
    
    		while((line = br.readLine()) != null){
    			builder.append(line).toString() ;
    		}
    		text.setText(builder.append(line).toString());
    		myInput.close();
    
    	} catch (Exception e) {
    		System.err.println("Error: " + e.getMessage());
    	}
    }
    please help me find the problem and thanks in advance

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    StringBuilde didn't append with the line-breaks and all. In what format your file content with you?

  3. #3
    bulldo is offline Member
    Join Date
    Jul 2010
    Posts
    8
    Rep Power
    0

    Default

    hello !!

    I got the solution :D thanks any way :)
    here is the code :

    Java Code:
    while((line = br.readLine()) != null){
    	builder.append(line);
    	builder.append("\n");
    }
    text.setText(builder.toString());

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Use system properties to define those values.

    Java Code:
    System.getProperty("line.separator")

  5. #5
    bulldo is offline Member
    Join Date
    Jul 2010
    Posts
    8
    Rep Power
    0

    Default

    I've noticed that the undo/redo are not availble in my text zone, I can do copy paste and cut but not undo/redo !
    Is there any easy way to have these two functions ?
    what are the main steps that I should follow and thanks in advance

Similar Threads

  1. How enter this mode-gui/design-view/code-view
    By lse123 in forum NetBeans
    Replies: 0
    Last Post: 02-28-2010, 10:09 PM
  2. Updating a view using actions in a seperate view
    By xcallmejudasx in forum Eclipse
    Replies: 0
    Last Post: 10-24-2008, 10:24 PM
  3. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 08:02 PM
  4. Replies: 1
    Last Post: 07-19-2007, 12:20 AM
  5. Replies: 0
    Last Post: 07-17-2007, 04:30 PM

Posting Permissions

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