Solved

Displaying file content.

Posted on 2004-08-02
6
278 Views
Last Modified: 2010-08-05
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.

Thanks
Raghava
0
Comment
Question by:raghava_dg
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 20 total points
ID: 11698773
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) {
                  e.printStackTrace();
            }
            getContentPane().add(pane, BorderLayout.CENTER);
0
 

Author Comment

by:raghava_dg
ID: 11699216
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 .
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11700931
you could use JOptionPane:
JOptionPane.showInternalMessageDialog(frame, "information","information", JOptionPane.INFORMATION_MESSAGE);

or:
JDialog dialog = new JDialog();
//use what CEHJ suggest. Replace the last instruction with the following
dialog.getContentPane().add(pane,BorderLayout.CENTER);
dialog.show();


Bye, Giant.
0
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.

 

Author Comment

by:raghava_dg
ID: 11704107
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 ..
0
 

Author Comment

by:raghava_dg
ID: 11727672
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?
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11733089
sure, it could be done.
0

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTTPSessionBindingListernter not configured in deployment descriptor 2 65
java jdbc batch example 8 40
servlet example issue 6 46
mysql jsp example issue 32 48
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question