File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Converting a Word doc into a Gui. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Converting a Word doc into a Gui." Watch "Converting a Word doc into a Gui." New topic
Author

Converting a Word doc into a Gui.

Scotty Steven
Ranch Hand

Joined: Jan 27, 2012
Posts: 80
I have a word document (a tutorial) that I want to open in a swing type window. It has both text and pictures. What I'm looking to accomplish is when the user selects the item from a menu in a larger program, this event will a new class and in that class, a "window" opens displaying the pics and text, pretty much as formatted. I want to use, but have no clue as to accomplish it. I'm new to programming, and have tried this on my own with no luck at all, so help will be appreciated.

If you tell me how to upload the file, I will, but I get a: Files with the extension (.rar)(docx)(rtf) are not allowed as attachment in the message. each time I try.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

You will have to rephrase your requirement. Frankly speaking, I (at least) cannot figure out what you are trying to do here. Uploading a file typically indicates a server side component. What is it's relation to the Swing UI? Regarding richly formatted text component, you might want to check out http://docs.oracle.com/javase/tutorial/uiswing/components/generaltext.html

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Scotty Steven
Ranch Hand

Joined: Jan 27, 2012
Posts: 80
I wanted to upload the word document that I'm working with to this board, but but the board doesn't allow .rar, .docx, or .rtf files to be attached, so if someone needs the file, I will need your emaill address.

I want to take the contents of a word document, that includes both pictures and text, and incorporate it into a larger program. That's all. Nothing nearly as fancy as your post indicated.

I hope that makes things a little clearer.
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

So what you're saying is that you'd like to display your Word document in a Java program, right?

Apache POI (<-link) might be of some use.


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Scotty Steven
Ranch Hand

Joined: Jan 27, 2012
Posts: 80
@Riaan Nel

I am trying to run Apache POI, but I get the following error:

Failed to load Main-Class manifest attribute from
C:\Users\Scotty\Desktop\poi-3.7\poi-3.7-20101029.jar

Any ideas why this might be?
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1666
    
    7

You can't run POI as a stand-alone program, but it offers an API you can call from within your own program if you put the JAR file on your application's classpath.
By the way, a simpler alternative might be using something like a JTextPane to display an HTML formatted document.
You wouldn't need to mess about with external libraries like Apache POI if you save the document as a web page (.html) in Word - usually yielding some of the most horrific HTML of all time.
Don't know if that's a usable alternative, but I figured it was worth mentioning.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Writing a Word viewer component in Swing would be a major undertaking; you could probably make money selling that. If this viewer component isn't the main point of your app, I predict that you will end up not doing it.

What's the advantage of displaying such a document in a Swing component instead of using an existing desktop app (assuming that some office app is installed, obviously)?
Scotty Steven
Ranch Hand

Joined: Jan 27, 2012
Posts: 80
I guess I am not explaining myself correctly. I have a tutorial. It happens to be saved as a word document. I want to take each part of the word document. cut them out of the document, and past them into a frame. Once built, I never want to use the word file again.

So really, what I'm asking is, how can I display text and pictures together, at the same time in a frame. There might be a paragraph of text, then a picture, then some more text, a table, more text, ect.
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Tim Moores wrote:Writing a Word viewer component in Swing would be a major undertaking; you could probably make money selling that. If this viewer component isn't the main point of your app, I predict that you will end up not doing it.

What's the advantage of displaying such a document in a Swing component instead of using an existing desktop app (assuming that some office app is installed, obviously)?

@OP - I agree with Tim. When I need some or other external functionality (e.g. opening a Word document), I tend to try and pass it to an external application that knows how to handle it, rather than reinvent the wheel.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1666
    
    7

I want to take each part of the word document. cut them out of the document, and past them into a frame. Once built, I never want to use the word file again.


In that case I would certainly externalize the content you want to display in HTML form, rather than as a MS Office document.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
There is no principal difficulty walking through a document using the Apache POI library Riaan mentioned, and building a corresponding tree of Swing components. It's just a very involved process if you want to process all the options a typical word document can have. Maybe the documents you're working with do not use all those options, which would make the endeavour more feasible.
Scotty Steven
Ranch Hand

Joined: Jan 27, 2012
Posts: 80
All the doc I has is some plain old text text with the following features: times new roman, size 11 and 18, bullets, some bold, some underline.

Several jpeg

a couple of tables.

That's it. Nothing that special.

I could turn it into a htlm in a couple of minutes, but I would then be asking the question, how do I display an html page inside a frame?


Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

JEditorPane could be of some use, unless you really want separate components for everything.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1666
    
    7

Well, that was the whole point of the suggestion for a move towards HTML: Swing offers out-of-the-box support for rendering HTML content in its components.
JEditorPane or its subclass JTextPane are good examples of this, and seem very usable in your case.
Scotty Steven
Ranch Hand

Joined: Jan 27, 2012
Posts: 80
That's it! I'm looking for the example on the top right corner. OK. Time to go play. Thanks everyone.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting a Word doc into a Gui.
 
Similar Threads
create new session in jsp
junit4 suite
"target=_blank" makes validation errors appear in new window
Opening Windows
best way to update a JList