Search code examples
javauser-interfacejeditorpane

How to enable javascript in a java browser?


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();
            };

        }});





};

}

Solution

  • 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.