Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7428941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:53:27+00:00 2026-05-29T08:53:27+00:00

I asked about this before, but, I decided to start a new thread with

  • 0

I asked about this before, but, I decided to start a new thread with a SCCE, it compiles sucessfully but it doesn’t insert the image. Can anyone troubleshoot as to why it does this? Thanks, Chris.

Here is the full code:

package mathnotesplus;

import java.awt.Dimension;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.SwingUtilities;
import javax.swing.JPanel;
import javax.swing.JTextPane;

import javax.swing.JFrame;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.text.*;
/**
 *
 * @author ChrisCates
 */
public class MathNotesPlus extends JFrame implements TreeSelectionListener {

    /**
     * @param args the command line arguments
     */
    public MathNotesPlus() {
        setTitle("Math Notes Plus");
        setSize(800, 600);
        initUI();
    }


    JPanel panel;
    JTextPane textpane;
    JTree navigation;
    StyledDocument document;

    public void initUI(){
        //The panel.
        panel = new JPanel();
        //Textpane and JTree
        textpane = new JTextPane();
        navigation = new JTree();
        navigation.addTreeSelectionListener(this);
        //Preferred Resolution Size
        navigation.setPreferredSize(new Dimension(100, 600));
        textpane.setPreferredSize(new Dimension(700, 600));

        //Insertion of image into the document.
        try {
            document = (StyledDocument)textpane.getDocument();
            Style style = document.addStyle("StyleName", null);
            StyleConstants.setIcon(style, new ImageIcon("sigma.png"));
            document.insertString(document.getLength(), "ignored text", style);
        } catch (BadLocationException e){
            System.err.println("ERROR");
        }

        //Putting everything into the program.
        panel.add(navigation);
        panel.add(textpane);        
        add(panel);
        pack();


    }

    public static void main(String[] args) {
        // TODO code application logic here
        SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            MathNotesPlus app = new MathNotesPlus();
                app.setVisible(true);
            }
        });
    }

    @Override
    public void valueChanged(TreeSelectionEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:53:27+00:00Added an answer on May 29, 2026 at 8:53 am

    Base on this working example (a very close variant of your code) that works, I can only guess that your code is failing because the image is not being found.

    import java.awt.Dimension;
    import java.awt.Image;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import javax.swing.text.*;
    import java.net.URL;
    import javax.imageio.ImageIO;
    
    public class MathNotesPlus extends JFrame {
    
        JPanel panel;
        JTextPane textpane;
        StyledDocument document;
    
        public MathNotesPlus() {
            setTitle("Math Notes Plus");
            setSize(800, 600);
            initUI();
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }
    
        public void initUI(){
            //The panel.
            panel = new JPanel();
            //Textpane
            textpane = new JTextPane();
            textpane.setPreferredSize(new Dimension(700, 600));
    
            //Insertion of image into the document.
            try {
                Image image = ImageIO.read(new URL(
                    "http://pscode.org/media/stromlo1.jpg"));
    
                document = (StyledDocument)textpane.getDocument();
                Style style = document.addStyle("StyleName", null);
                StyleConstants.setIcon(style, new ImageIcon(image));
                document.insertString(document.getLength(), "ignored text", style);
            } catch (Exception e){
                e.printStackTrace();
            }
    
            //Putting everything into the program.
            panel.add(textpane);
            add(panel);
            pack();
        }
    
        public static void main(String[] args) {
            // TODO code application logic here
            SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                MathNotesPlus app = new MathNotesPlus();
                    app.setVisible(true);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've asked a question about this class before, but here is one again. I've
Im sorry if this been asked before, but couldnt find anything about this particular
Okay I know I asked about this before, and the answer was basically cache
There seem to be many questions asked about this subject here on stackoverflow, but
I asked a similar question about this previously, but I did not specify that
Got a little problem i asked about it before but maybe i didnt ask
I have asked this question before - but I have spent some time thinking
Now this question has been asked before but I am not able to get
I have asked aqbout timezones and date/time before but this is a more specific
I know this has been asked before but none of the cases I've seen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.