• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

Displaying file content.

Hi ,

I am very new to Java swings. No I am stuck in one prob.

After chooseing a file from showOpenDialog() I need to display the content of the file to user. How we can display the file content in swings ?

Please help me out.

  • 3
  • 2
1 Solution
Use a JEditorPane and add it to your JFrame:

            JEditorPane pane = new JEditorPane();
            try {
                  pane.getEditorKit().read(new java.io.FileReader("yourFile.txt"), pane.getDocument(), 0);
            catch (Exception e) {
            getContentPane().add(pane, BorderLayout.CENTER);
raghava_dgAuthor Commented:
Thank you for the quick help . but my main window in JPanel (inside that i have tabs) .
but getContentPane() is a method on JFrame .  how can I use this. my problem is a new window should pop up displating the file content . I am very new to swings . please help me out .
you could use JOptionPane:
JOptionPane.showInternalMessageDialog(frame, "information","information", JOptionPane.INFORMATION_MESSAGE);

JDialog dialog = new JDialog();
//use what CEHJ suggest. Replace the last instruction with the following

Bye, Giant.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

raghava_dgAuthor Commented:
thanks to both CEHJ and Giant2 . It worked out . I don't know how to share the points to both of you i will try it ..
raghava_dgAuthor Commented:
hey , one more thing ....

is it possible to open the file depending on the file type ?
for example if its a xls the it should open in excell . can it be done?
sure, it could be done.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now