Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Text and picture in a frame

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Text and picture in a frame

    Good evening

    I have a word document (instructions) that I want to place in in a frame in a program that I'm working on. I have no clue how to do it. I've played around with it, but no luck on my own. In the attached rar is a copy of the file that I want to convert.

    Thanks for any help that you can provide.
    Attached Files Attached Files


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Text and picture in a frame

    Place your code here, what have you tried so far?

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Text and picture in a frame

    OK, so, I redid the file as an rtf. I can run it with the following code, but i loose the pictures. I've attached the rtf file (in rar compression). Any idea how to fix the pictures so they display?

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.rtf.*;
    import java.io.*;
     
    public class RTFView extends JFrame
    {
    	public static void main(String[] args)
        {
          // Create an instance of the test application
          RTFView mainFrame = new RTFView();
          mainFrame.setVisible(true);
      	}// end main()
     
    	public RTFView()
    	{
    		//Delcarations
    		int x = 800;
    		int y = 600;
    		String title = "RTF Viewer";
    		String file = "Method Doc.rtf";
     
    		setTitle(title);
    		setSize(x, y);
    		setBackground(Color.gray);
    		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    		getContentPane().setLayout(new BorderLayout());
     
    		JPanel topPanel = new JPanel();
    		topPanel.setLayout(new BorderLayout());
    		getContentPane().add(topPanel, BorderLayout.CENTER);
     
    		// Create an RTF editor window
    		RTFEditorKit rtf = new RTFEditorKit();
    		JEditorPane editor = new JEditorPane();
    		editor.setEditorKit(rtf);
    		editor.setBackground(Color.white);
     
    		// Scroll pane
    		JScrollPane scroller = new JScrollPane();
    		scroller.getViewport().add(editor);
    		topPanel.add(scroller, BorderLayout.CENTER);
     
    		// Load an RTF file
    		try
    		{
    			FileInputStream fi = new FileInputStream(file);
    			rtf.read(fi, editor.getDocument(), 0);
    		}
     
    		catch (FileNotFoundException e)
    		{
    			System.out.println("File not found");
    		}
     
    		catch (IOException e)
    		{
    			System.out.println("I/O error");
    		}
     
    		catch (BadLocationException e)
    		{
    		}
    	}// end RTFView()
     
    }// end class
    Attached Files Attached Files

Similar Threads

  1. Replies: 1
    Last Post: January 19th, 2012, 03:44 PM
  2. Converting a picture made up of 0s and 1s into a colored picture??
    By Kranti1992 in forum Java Theory & Questions
    Replies: 10
    Last Post: November 21st, 2011, 06:25 PM
  3. Showing a picture in a GUI
    By joachim89 in forum AWT / Java Swing
    Replies: 1
    Last Post: February 15th, 2010, 02:42 PM
  4. Modify Colors in a Picture
    By theuniverse in forum Java Theory & Questions
    Replies: 0
    Last Post: October 17th, 2009, 04:49 PM
  5. Need help with a Picture!
    By Scout in forum Java Theory & Questions
    Replies: 1
    Last Post: October 12th, 2009, 05:33 PM