JEditorPane

JEditorPane

A text pane that can be used to edit various types of content, including HTML and RTF.

getClass() 

This method returns an object of type Class that identifies the class of the current object.

getResource () 

The getresource() method finds a resource with a given name. This method return the URL object.

getResource(String name)

Here,  name of the desired resource.

Setpage()

The setPage() method can be used to Sets the current URL being displayed.

Program 

jhjn

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.io.IOException;

class Frame extends JFrame {
  
    
    Frame()
    {
        setTitle("JEditorPane");
        setLayout(new FlowLayout());
        setJEditorPane();
        setSize(700,350);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    private void setJEditorPane()
    {
        JEditorPane je = new JEditorPane();
        try{
            je.setPage(getClass().getResource("1.html"));
        }catch(IOException ioe)
        {
            JOptionPane.showMessageDialog(rootPane, "Unable to load File");
        }
        JScrollPane js = new JScrollPane(je);
        js.setPreferredSize(new Dimension(300,300));
        add(js);
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
       Frame fr = new Frame();
    }
}

Leave a Comment