CONSTRUCTORS OF JTEXTPANE:
JEditorPane(URL)JEditorPane(String)
These two constructor are used to create editor pane that has a text of specified URL.
setPage(URL)
setPage(String)
setPage(String)
Used to load a page on jtext pane of specified URL.
CODING:
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
class myjframe1 extends JFrame implements ActionListener
{
JMenuBar menuBar = new JMenuBar();
JMenu file = new JMenu();
JMenuItem open = new JMenuItem();
JTextPane textpane =new JTextPane();
public myjframe1()
{
setTitle("JTextPane");
setSize(300, 200);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
textpane = new JTextPane();
textpane.setPreferredSize( new Dimension( 800, 800 ) );
menuBar.add(file);
file.setText("File");
file.add(open);
setJMenuBar(menuBar);
open.setText("OPEN");
setLayout(new FlowLayout(FlowLayout.CENTER));
JScrollPane js = new JScrollPane(textpane,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
add(js);
open.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == open)
try
{
JFileChooser open = new JFileChooser();
int option = open.showOpenDialog(this);
textpane.insertIcon( new ImageIcon (open.getSelectedFile().getPath()));
}
catch(Exception ae)
{
System.out.println(ae);
}
}
}
class text
{
public static void main(String args[])
{
myjframe1 x= new myjframe1();
}
}
0 comments:
Post a Comment