Wednesday 12 August 2015

Filled Under: ,

How To Open Text File In JTextArea Using File Chooser In Java

As we see in most popular text editors such as notepad or word that there is option of open file by using this option we can open any text file and can perform several operations provided by that editors.This tutorial shows how to create a your own text editor that can read text files.To perform this task we need one text area to show a content of a file and a file chooser to select file as shown in below code.

RELATED TUTORIALS:


CODING:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class myjframe1 extends JFrame implements ActionListener
{
JTextArea textArea = new JTextArea();
JMenuBar menuBar = new JMenuBar();  
JMenu file = new JMenu();
JMenuItem open = new JMenuItem();


public myjframe1()
{

setTitle("Opening Txt File");
setSize(300, 200);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);      
textArea = new JTextArea(40,40);
menuBar.add(file);
file.setText("File");
file.add(open);
setJMenuBar(menuBar);
open.setText("OPEN");
setLayout(new FlowLayout(FlowLayout.CENTER));
JScrollPane js = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 
add(js);
open.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == open)

try
{
JFileChooser open = new JFileChooser();
int option = open.showOpenDialog(this);
File f1 = new File(open.getSelectedFile().getPath());
FileReader fr = new FileReader(f1);
BufferedReader br = new BufferedReader(fr);
String s;
while((s=br.readLine())!=null)
{
textArea.append(s + "\n");
}
fr.close();
}
catch(Exception ae)
{
System.out.println(ae);
}
}
}
class text
{
public static void main(String args[])
{
myjframe1 x= new myjframe1();
}
}

OUTPUT:






23 comments:

  1. OpenText manages content or unstructured data for large enterprises, government agencies, and other service firms. OpenText Course completely aims its products at address information management requirements, large volumes of content, compliance and other mobile and online experience management.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot in Oracle SOA Online Training. it is really explainable very well and i got more information from your blog.

    ReplyDelete
  4. Payroll management is truly a significant part these days. Every organization has its own employees. Employers want to manage their pay. The yearly medical benefit is QuickBooks Payroll Support Phone Number The employer needs to allocate.

    ReplyDelete
  5. Though these features appear to be extremely useful as well as in fact these are typically so, yet there are numerous loopholes that will trigger a few errors. These errors might be resolvable at QuickBooks Support Number by our supremely talented, dedicated and well-informed tech support team team.

    ReplyDelete
  6. QuickBooks Enterprise Support Phone Number Edition is not only an accounting software but a complete ERP solution within itself. Now days, it absolutely was evident that Medium Scale Business and Industry specific business like Manufacturing, Contractors, Wholesalers, Retail, Professional Services etc. invests good amount of money regarding the accounting software to make certain data accuracy, timely delivery of information so they will be able to give attention to their particular workfare to boost the productivity and therefore increased business. QuickBooks Enterprise edition is a one stop seek out such style of business and QuickBooks Enterprise Support may be the one stop solution provider for detecting and fixing QuickBooks Enterprise Accounting problems and technical issues.

    ReplyDelete
  7. QuickBooks Premier is an accounting software that includes helped you grow your business smoothly. It includes some luring features which make this software most desirable. In spite of all of the well-known QuickBooks Premier features you may find difficulty at some steps. QuickBooks Payroll Support Phone Number is the greatest destination to call in the period of such crisis.

    ReplyDelete
  8. As well as with this particular, our QuickBooks Technical Support Phone Number team has much knowledge and information regarding QuickBooks tools such as QuickBooks database server manager and so many more. Many users always think about QuickBooks journal entry that simple tips to easily create. So don’t worry about this our excellent QuickBooks team provide you every understanding of this topic also.

    ReplyDelete
  9. If you need the help or even the information about it, our company has arrived now to do business with you with complete guidance combined with demo. Connect to us anytime anywhere. Only just contact us at QuickBooks Payroll Support USA . Our experts professional have provided a lot of the required and resolve all type of issues related to payroll.

    ReplyDelete
  10. Issues like these and all sorts of the other complex ones are very easily resolved by our team at QuickBooks 247 Support Phone Number. Our customer care executives are experienced, talented, hardworking an efficient. They put their hundred percent efforts and then make certain to have you avail their 24*7 assistance. Contact us at our toll-free number or drop us a mail.

    ReplyDelete
  11. QuickBooks accounting software is integrated with different items like QuickBooks Enterprise(developed by Intuit) and tools like QuickBooks file doctor. And it also offers a number of incredible features (Business plans, cash flow projections, and advanced inventory ) making it unique from other Quickbooks product. It really is most suitable for small to medium businesses though it really is incredibly expensive. No doubt, this has good compatibility with virtually every type of Windows OS, Mac OS, iOS, and Android. Yet you may possibly require a competent QuickBooks Enterprise Support to handle payroll management, account management, inventory, and other accounting activities. AccountWizy provides you a perfect and efficient QuickBooks Enterprise customer care making it all possible.

    ReplyDelete
  12. Stuck in a few basic issue? Will likely not think twice to offer us a call at QuickBooks Support Phone Number Since quantity of issues are enormous on occasion, they might seem very basic to you personally so when an effect might make you're taking backseat and you may not ask for every help. Let’s update you aided by the indisputable fact that this matter is immensely faced by our customers. Do not worry most likely and e mail us at our QuickBooks Support Phone Number Our customer service executives are particularly customer-friendly helping to make certain that our customers are pleased about our services.

    ReplyDelete
  13. Our support also also contains handling those errors that always occur once your type of QuickBooks Enterprise Technical Support happens to be infected by a malicious program like a virus or a spyware, which may have deleted system files, or damaged registry entries.

    ReplyDelete
  14. The best solutions are imperative for the growth of the company. Therefore, QuickBooks Tech Support Phone Number is present for users across the world as the best tool to offer creative and innovative features for business account management to small and medium-sized business organizations.

    ReplyDelete
  15. But, i am at your side. In the event that you hire our service, you are receiving the best solution. We're going to assure you as a result of error-free service. QuickBooks Tech Support Number is internationally recognized.

    ReplyDelete
  16. QuickBooks Customer Service Number really is nearly not possible not to wander away once in a very whereas following the written account to control the accounts. That is why intuit created QuickBooks: associate degree accounting and management code. Today, QuickBooks is the most used accounting and management code out there.

    ReplyDelete
  17. QuickBooks users tend to be found in situations where they need to face most of the performance and some other errors due to various causes in their computer system. If you'd like any help for QuickBooks Support Phone Number to get the solution to these errors and problems, you can easily connection with QuickBooks support contact number and acquire instant help with the guidance of your technical experts.

    ReplyDelete
  18. The group deployed at the final outcome of QuickBooks Helpline Number takes great proper care of all from the issues for the software. QuickBooks Support telephone number have a team of experts which can be pro in handling all of the issues because of this incredible software.

    ReplyDelete
  19. QuickBooks has availed many further versions with this specific software namely QuickBooks Pro, QuickBooks Premier, QuickBooks Enterprise, QuickBooks Point of Sale, QuickBooks Payroll, QuickBooks Support Phone Number, QuickBooks Mac and QuickBooks Windows & we fix all Quickbooks tech issues. Amongst a number of these versions you may select the the one that suits your on line business the best.

    ReplyDelete
  20. QuickBooks Support Phone Number software is built to solve the problems of small and enterprise business owners. There are a large number of QB users around the world. Let us know if you are looking for QuickBooks technical support. Speaking with a certified QuickBooks expert can help you to save time and money.

    ReplyDelete
  21. Take delight in with an array of outshined customer service services for QuickBooks via QuickBooks Support Phone Number at any time and from anywhere. It signifies that one can access our tech support for QuickBooks at any moment. Our backing team is dedicated enough to bestow you with end-to-end QuickBooks solutions when you desire to procure them for every single QuickBooks query.

    ReplyDelete
  22. QuickBooks Payroll Technical Support Number: A unique method to manage your employees’ salary and other payroll functions of the business. QuickBooks Payroll enables users to view and approve employee work time and process payroll within 5 minutes.

    ReplyDelete
  23. I honestly appreciate the blog you have posted. Really looking forward to this kind of words.

    ReplyDelete