Solved

Displaying file content.

Posted on 2004-08-02
6
271 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 42
Books that can get me started on JAVA 2 56
wordcount challenge 11 76
wordappend challenge 8 85
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now