Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Displaying file content.

Posted on 2004-08-02
6
Medium Priority
?
285 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 60 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 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