0

Possible Duplicate:
jEditorPane as a web browser

I have a small relativly simple web browser and I wish to enable Javascript in the browser .How would I go about doing this ? I wish to keep the browser relativly simple also but any improvments or suggestions would be greatly welcomed. Heres the code . Thanks in advance.

public class javamark13 {

static String command ;
static JEditorPane epane;
static JPanel panel;
static JFrame  frame ;
static JTextField field ;
static JLabel  label;
static JButton  button ;
static JScrollBar bar ;


public static void main (String[] args){
    //design of the jpanel  jframe
    frame=new  JFrame ("Lotta Browser ");
    frame.setVisible(true );
    frame.setLocation(1,1);
    frame .setSize(1000,700);
    panel =new JPanel ();
    label=new JLabel("                         Enter a URL");
    label.setBounds(50,5,50,20);
    panel.add(label);
    button=new JButton("Search");
    button.setBounds(870, 0, 110, 25);

    frame .setContentPane(panel);
    panel.setBackground(Color.gray);
    panel .setLayout(null);
    epane=new JEditorPane();
    epane.setEditable(false);
    epane .setBounds(1, 25, panel.getWidth(),panel.getHeight());
    panel.add(epane);
    field=new JTextField ();
    panel.add(button);
    field.setBounds(75,1,panel.getWidth()-191,23);
    panel.add(field);




    //******************************************************


    button.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent arg0) {
            command =field.getText();
            String  http="http://www.";
            String com=".com/";
            command=http +command+com;
            field.setText(command);
            try {
                epane.setPage(new URL(command));
            } catch (MalformedURLException e) {

                e.printStackTrace();
            } catch (IOException e) {

                e.printStackTrace();
            };

        }});





};

}
Community
  • 1
  • 1
  • 1
    "I wish to keep the browser relativly simple" I think you'll find your two goals at odds. The browser DOM is pretty much a poster child of design bloat, and your first step in implementing Javascript support would be providing HTML DOM compatible interfaces to your browser. This is why people use rendering engines that already do most of the work, like WebKit or Gecko. – millimoose Dec 21 '12 at 00:32

1 Answers1

2

See the answer posted here: https://stackoverflow.com/a/4154015/177154

In short: JEditorPane has limited html and css support and does not support javascript or applets.

Community
  • 1
  • 1
draganstankovic
  • 5,382
  • 1
  • 27
  • 33