Results 1 to 2 of 2
  1. #1
    tskarthic is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default display huge size file in jtextarea

    Hello Friends,

    I want to display huge size files (<100 MB) in JTextArea. But it is not displaying the contents. I use the below code to test it. But it is also not showing. Please help me.

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    
    public class ViewOrder extends JFrame{
    JPanel pnlText, pnlBody, pnlFooter;
    JButton btnViewOrder;
    JButton btnReturnToOrderSystem;
    JLabel jl;
    JTextArea jta;
    Container contentpane;
    
    public ViewOrder(){
    super("View Order");
    contentpane = getContentPane();
    contentpane.setLayout(new BorderLayout());
    pnlText = new JPanel();
    pnlBody = new JPanel();
    pnlFooter = new JPanel();
    jta = new JTextArea(250, 250);
    jta.setFont(new Font("Serif", Font.PLAIN, 12));
    
    // Set lineWrap and wrapStyleWord true for the text area
    jta.setLineWrap(true);
    jta.setWrapStyleWord(true);
    jta.setEditable(false);
    
    // Create a scroll pane to hold the text area
    JScrollPane jsp = new JScrollPane(jta);
    
    // Set BorderLayout for the panel, add label and scrollpane
    pnlBody.add(jsp, BorderLayout.CENTER);
    
    jl = new JLabel("Text retrieved from file:");
    btnViewOrder = new JButton("View Order");
    btnReturnToOrderSystem = new JButton("Return to Order System Menu");
    pnlText.add(jl);
    pnlFooter.add(btnViewOrder);
    pnlFooter.add(btnReturnToOrderSystem);
    contentpane.add(pnlText,BorderLayout.NORTH);
    contentpane.add(pnlBody,BorderLayout.CENTER);
    contentpane.add(pnlFooter,BorderLayout.SOUTH);
    setSize(500, 500);
    setVisible(true);
    
    btnViewOrder.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    //Read from file
    try{
    File openAs = new File("D://mgc12ux_network.log");
    // This file is huge in size. More than 100 MB
    FileReader in = new FileReader(openAs);
    jta.read(in, openAs.toString());
    }
    catch(java.io.IOException ex){
    System.out.println("Cannot read from file");
    }
    }
    });
    
    btnReturnToOrderSystem.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    setVisible(false);
    //OrderSystem os = new OrderSystem();
    //os.setVisible(true);
    }
    });
    }
    
    public static void main(String[] args){
    new ViewOrder();
    }
    }

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

    Default

    I think that trying to load and display a very large file is not what you want to do, that instead you might want to stream a reasonable part of the file into a buffer that is viewed as it is needed, but I'm no expert on this.

Similar Threads

  1. Replies: 10
    Last Post: 05-24-2010, 08:25 PM
  2. Replies: 17
    Last Post: 07-13-2009, 05:44 AM
  3. Replies: 6
    Last Post: 03-09-2009, 03:02 PM
  4. Constant size for JTextArea
    By itaipee in forum AWT / Swing
    Replies: 1
    Last Post: 12-30-2008, 04:12 PM
  5. [SOLVED] Last line in JTextArea wont display
    By Chris.Brown.SPE in forum Advanced Java
    Replies: 5
    Last Post: 04-11-2008, 01:52 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
  •