How to display text file text in aTextArea component

Hello
ive managed to display the text file text in the console, but i want it to show up in the textArea component i have in a frame,
it seems to display the last character . in the text area
wheres the rest of the text...this was a lot easier in VB.NET
any help would be much appreciated
heres my code...
private void openButtonActionPerformed(java.awt.event.ActionEvent evt)  {//GEN-FIRST:event_openButtonActionPerformed
// TODO add your handling code here:
     FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files Only","txt");
     editorFileChooser.setFileFilter(filter);
     int returnVal = editorFileChooser.showOpenDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION){
          System.out.println("You chose to open this file: " + editorFileChooser.getSelectedFile().getName());
          openFileName = editorFileChooser.getSelectedFile().getName();
          openFile = new File(openFileName);
          try {
               this.readFile = new FileReader(openFile);
          } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          int inputCharacters;
     try {
     while ((inputCharacters = readFile.read()) != -1){
          System.out.print((char)inputCharacters);
          char[]CHARAARAY = {(char)inputCharacters};
          s3 = new String(CHARAARAY );
          this.editorTextArea.setLineWrap(true);
     this.editorTextArea.setText(s3.toString());
     readFile.close();
     catch(IOException ex){
          System.out.println();
}//GEN-LAST:event_openButtonActionPerformed

>
wheres the rest of the text...this was a lot easier in VB.NET>If you only need to code for Windows, use VB. For code that works on computers, learn the Java idioms, especially with regard to X-plat issues with Files.
>
heres my code...>That was a code snippet. You will get better chance of help around these parts, if you can prepare an SSCCE. The code below* is an SSCCE.
There was a basic problem in the logic of that code, that resulted in the assumption (by the JRE) that every file the user attempted to load, was located in the 'current directory'. It was fixed by abandoning the String based file name of the file, and instead setting openFile to the selected file in the chooser. I also demolished the loading code by replacing the JTextArea with a JEditorPane (much easier).
* Altered code;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.io.*;
class TestLoadFile extends JPanel {
  JFileChooser editorFileChooser;
  File openFile;
  JEditorPane editorTextArea;
  TestLoadFile() {
    super(new BorderLayout());
    editorTextArea = new JEditorPane();
    add(
      new JScrollPane(editorTextArea),
      BorderLayout.CENTER );
    JButton load = new JButton("Load File");
    load.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
          openButtonActionPerformed(ae);
    add( load, BorderLayout.SOUTH );
    editorFileChooser = new JFileChooser();
  public static void main(String[] args) {
    TestLoadFile tlf = new TestLoadFile();
    JOptionPane.showMessageDialog(null, tlf);
  Dimension preferredSize = new Dimension(600,400);
  public Dimension getPreferredSize() {
    return preferredSize;
  private void openButtonActionPerformed(java.awt.event.ActionEvent evt)  {
    //GEN-FIRST:event_openButtonActionPerformed
  // TODO add your handling code here:
    FileNameExtensionFilter filter = new
      FileNameExtensionFilter("Text Files Only","txt");
    editorFileChooser.setFileFilter(filter);
    int returnVal = editorFileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION){
      System.out.println("You chose to open this file: " +
        editorFileChooser.getSelectedFile().getName());
      // wrong!
      //openFileName = editorFileChooser.getSelectedFile().getName();
      //openFile = new File(openFileName);
      // right!
      openFile = editorFileChooser.getSelectedFile();
      try {
        editorTextArea.setPage(openFile.toURI().toURL());
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
  }//GEN-LAST:event_openButtonActionPerfor
}

Similar Messages

  • How to display text on last but one page in SAPSCRIPTS

    how to display text on last but one page in SAPSCRIPTS

    u have create one Foooter window , this has to be called in  only One Page.So hardcode /assign this window to only one PAGE number.
    regards
    Prabhu

  • How to display texts automatic. besides entered value for a field in Trans.

    How to display texts automatically besides the entered value for a field in a standard transaction screen. For example you have a value table and a text table associated to it. Then on entering the value field and pressing enter the text associated should get displayed immediately besides the value. Like if you have 'LOC' as the value and 'Location' as the text associated to it, on entering this value 'LOC', you automatically get the text 'Location' printed besides it automatically in a transaction screen ?
    Message was edited by: Sarika Kedia

    Hi sarika,
    Welcome to SDN.
    1. first of all, such display of text,
       is not automatic.
       (it appears to be automatic)
    2. At design time,
       a) take one extra field for text
         and mark it as OUTPUT ONLY
    3. Then in PBO coding,
        call some module, and in that module
        write code
    4. The code should be to
       select from TEXT Table
       into the work area.
    EG. THE SCREEN TEXT FIELD NAME IS
    T510A-FIELDNAME.
    CLEAR t510a.
      SELECT SINGLE * FROM t510a INTO t510a
      WHERE trfar = FIELVALUE.
    5. This will take care of
       displaying the text value of that field.
    regards,
    amit m.

  • How to display text on last but one page

    how to display text on last but one page

    Hi Preeti,
      If u r working on a smartform then click on th window go to the condition tab there
      at the end u will find events click on the the event on which u want to trigger the 
      print.
      If u r working on a script then create a text element and call this text elemtn at
    the end of processing of the main window, this will make sure that thetext element
    is triggered only at the end.
    I hope that helps u , if not pls let me know.
    Regards,
    Vaibhav B Gawali.

  • How to display Pdf file in iPad site

    Hi
    How to display Pdf file in web page which can able to view in iPad safari?
    Thanks,
    Arun

    You can't really.
    You need to use DHTML in the swf-wrapper HTML file, usually a
    division wrapped iFrame, and load the PDF into the iFrame as an
    overlay to the Flash.

  • How to display Doc file format in the JEditPane?

    At this time , JEditPane supports RTF and HTML file format ,but
    Could anyone tell me how to display DOC file format using JEditPane
    or other JTextComponents?
    Thx a lot!
    Caton

    Hi,
    there is no support for doc files (M$ Word?) in Java. You would have to create your own classes for that eventually subclassing JEditorPane, EditorKit, Document etc. As well you'd need your own reader for the doc format.
    The problem I see with that however is that there is nothing such as thedoc file format. Microsoft just saves anything produced by MS Word into files ending with .doc. But, if there is anything such as a .doc file format, it changes more often than the weather in April.
    Ulrich

  • How to display the file status in the status bar?

    Hi all,
    Can anyone tell me how to display the file status in the status bar?
    The file status can consists: the type of the file, the size of the file etc..
    thanx alot..

        class StatusBar extends JComponent {
              JLabel l = new JLabel("ready");
            public StatusBar() {
                  super();
                  setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
                  add(l);
              public void setText( String prompt ) {
                   l.setText(prompt);
                   setVisible( true );
            public void paint(Graphics g) {
                  super.paint(g);
        }

  • How to display flash file in adf pages

    how to display flash file in adf pages need help

    Thanks all,
    It is resolved.
    the code i am using to display a flash is below.
    <f:verbatim>
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version
    =10,0,0,0" width="300" height="300" id="11gR1_aniH_grey" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="allowFullScreen" value="false" />
    <param name="wmode" value="transparent" />
    <param name="movie" value="mx2004demo.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#4d5c64" />     
    <embed src="../Images/mx2004demo.swf" quality="high" width="300" height="300" name="mx2004demo.swf" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false"
    type="application/x-shockwave-flash" wmode="transparent"
    pluginspage="http://www.adobe.com/go/getflashplayer" />
         </object>
    </f:verbatim>

  • How to display XSL file to ASPX in dreamweaver

    Hi,
    Just wondering how to display XSL file in ASPX page?
    I normally do it in ASP page by using server behaviour XSLT transformation and bind it to ASP page and this works very well.
    Now I am trying to use the same method and using ASPX page this time but this time there is no option from server behaviour where I can bind it to my ASPX.
    Can someone help or perhaps let me know where I can find the information how to do it?
    Thanks,
    Rush O

    You mean you want to see the XML source?
    You need to replace the characters '<' and '&' with corresponding entities '&lt;' and '&amp;'. You can use replaceAll, but do the ampersands first.
    Then I suggest you probably want to put them in a <PRE> block.

  • How to display RTF file and .doc file in JTextPane

    How to display RTF file and .doc file in JTextPane??

    Duplicate post
    http://forum.java.sun.com/thread.jsp?forum=57&thread=567029&tstart=0&trange=30

  • How to display text file in JSP?

    Hi,
    I am new to servlet/JSP/java programming.
    I have been able to download a file using ftp. I dont know who to display it in JSP.
    Here is my code. Any help will be appreciated...
    <%@ page import="java.util.*" %>
    <%@ page import="java.lang.*" %>
    <%@ page import="java.net.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="com.dmhistory.*" %>
    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <%
    byte[] bytes = new byte[4096];
    URL theUrl = new URL("ftp://user:passwd@host/migr/Movers_for_Ora8/BG/logs/FLD-PAC3-20020311.log");
    BufferedInputStream in = new BufferedInputStream(theUrl.openStream());
    BufferedOutputStream outstream = new BufferedOutputStream(new FileOutputStream( new File( "D:/temp/log.txt" )));
    int pos = in.read( bytes );
    while ( pos != -1) {
    outstream.write( bytes, 0, pos );
    pos = in.read( bytes );
    %>
    <%
    in.close();
    %>
    DONE!!!
    </body>
    </html>
    How can i display this downloaded file in the browser?
    I want to display it in the original format i.e which new line and carriage returns...line by line..
    Thanks,

    Hi,
    I finally go it to display. but now I have new problem. The browser shows the text without the /n/r.
    But when I view the source using 'view->source', if see that the text has got proper format with newline and carriage returns.
    Any ideas how to display it correctly in the browser?
    <%
                   URL theUrl = new URL("ftp://user:pwd@host/migr/Movers_for_Ora8/BG/logs/FLD-PAC3-20020311.log");
                   //URL theUrl = new URL("ftp://dbcmaint:[email protected]/migr/Movers_for_Ora8/SNP/logs/SNP-PAC2-20020314.log");
                   URLConnection uc = theUrl.openConnection();
                   InputStream content = uc.getInputStream();
                   BufferedInputStream in = new BufferedInputStream (content);
                   LineNumberReader lnr = new LineNumberReader (new InputStreamReader (in));
                   String tempStr = "";
                   String str = "";
                   while ((tempStr = lnr.readLine()) != null) {
                   str += (tempStr);
                        %>
                        <%=tempStr%>
                        <%tempStr = "";
                        %>
                   <%
                   in.close();
                   lnr.close();
              %>
    Thanks

  • How to display text file in  swing

    hello,
    I have screen where user enters batch number and number.
    when key is pressed a list is displayed on the screen.how to do this and how to relate my actionlistener with the function that generates the list...

    Hi,
    It is simple. Just create a button and add it to the action listener as button.addActionListener(this);
    Your class should extend ActionListener. and also there should be a method named - actionPerformed(ActionEvent avt) in your class
    Now inside this method, just compare the action as:
    if(avt.getSource()==button)
    // in this method, hjust take your file contents and display it on the same window, or create a new Frame here and display it in that window.
    If you want to display the file contents in the same window, then do the following.
    Declare a public JLabel variable for the class and create the JLabel along with the other components as usual but without giving any values. Now in the action part of the button, read the file contents in a string variable, and set the string to the jlabel as folows:
    label.setText(string);
    Hope it helps,
    Cochu.

  • How to display TEXT vertically in SMART FORM

    Hai,
    I need to display the column name of a table vertically (readable from bottom to top) in smart form.
    Could any one please tell me how to do this?
    Thanks & Best Regards,
    Maniyam Bhaskar.

    Hi,
    Go through these threads for the discussions happened on similar issue... hope it helps you..
    how to print text vertically in smart forms
    vertical and horizontal printing in same page with smartforms or sapscript
    Good luck
    Narin

  • How to display TEXT more than 500 char in a report as multiple lines.

    Hi Friends,
    i have a requirement like i should display Texts of length more than 500 Characters in a report( ALV LIST) as multiple lines
    I am fetching the data Using FM READ_TEXT
    the output im currently geeting with 150 Char in lenth as a single line
    How we can split the text into multiple lines in a report
    first i would like to know is it possible? if possible please give your valuable suggitions if not is there any alternative way to do this task.
    Thanks & regards
    kumar.

    Hi,
    This is possible but the Solution might not look Standard/Appropriate to you.
    In ALV, you can have Multiple Line Output...There is a Field in the Field Catalogue..called as Row_position...this is by default 0...which means Single row/Line ALV output....You can have this Value in the Range of 0 to 3.......A ALV field with row_position 1, will be displayed in the second line for every record...i.e. you will have multiple line for a single record of ALV.
    In your case......you can use this but you need to split your field in two fields.....but you may end up spliting a single word....but for that also you can design the logic of splitting the Fiel value at SPACE only......
    This may work.......and Sorry if not work......

  • How to display text in script as same as text in news paper

    Hi Expets
    I have a requirement i need to display text in script as same as text displayed in news paper
    with out creating any windows. iie ( Abcdef should be in one cloum after some space i need to display 1234)
    please let me know how can i achieve this
    Ex
    1.
    hi abcdef           12345
        abcedf          12345
    abcedf            12345
    Regards
    Suresh
    Edited by: suribabu124 on Jun 15, 2010 7:55 AM

    Hi,
    If you need to print a form like news paper you need go for multiple main windows.We know that we can use 99 main windows in one page.first create one main window and then leave a space then create one more window and select window type as mainwindow.
    while populating data,after completion of one main window the control will move to next main window,which is in the same page.
    Like this you need to analyse and code according to your requirement.

  • How to display text dynamically

    hello,
                                  i am working in dialog programing i need to display text which is save in a file and i want that whenever each new call screen i should display a text message from my flat file on the new screen ..... is there is a funda of xml?

    If the text is same for all the screens then copy it into a string or variable type c and write it on all the screens

Maybe you are looking for

  • Provisão de Serviço

    Boa noite a todos! Não estou conseguindo configurar um cenário de provisão de serviço em MM. Configurei o esquema de cálculo de serviço inserindo numa condição de provisão que criei a chave de operação BO1. Na transação OBYC informei para a operação

  • [SOLVED] LIRC config looks fine but my remote doesn't work.

    Following the steps of the wiki and this post I've created the configs file for lirc. But something is not working and I don't know how to find out what. I'm going to post some info so you guys can help me: ➜  ~  cat  /usr/lib/systemd/system/lirc.ser

  • BBM not working with one friend in particular

    Hi all! Lately I´ve been having a problem with BBM but only with one of my friends. She sends me messages that I don't receive and I send her messages that she doesn't receive. My messages appears like if they have been delivered, but not read. Howev

  • Delete photos in iPhoto and External HDD  simultaneously?

    Hello. I have 256SSD so its too little for me to save my large photo gallery on laptop. I use for it external HDD.  So i have next problem: when i delete photos in iPhoto they are deleted from only application and it stays in EXT HDD, but I want iPho

  • Stop-Motion Filming

    Hello, I am trying to make a stop-motion film and the photo duration settings aren't working properly. I am using iMovie 6.0.2. I am not using Ken Burns. The default photo duration seems to be 9:29. To change this default, I have found the answer in