1

This is the code Ive used to display the contents of a url in an editor pane

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    import java.net.*;


    public class header extends JFrame {

        private void initComponents() {

            jTextField2 = new JTextField();
            jTextField3 = new JTextField();
            jButton1 = new JButton();
            jScrollPane1 = new JScrollPane();
            jTextArea1 = new JEditorPane();

            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

            jButton1.setText("Load");
            jButton1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });

            jTextArea1.setEditable(false);
            jScrollPane1.setViewportView(jTextArea1);
            setSize(418,300);
            setVisible(true);
            GroupLayout layout = new GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                        .addComponent(jScrollPane1, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, 277, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextField3, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton1, GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                    .addContainerGap())
            );

            pack();
        }// </editor-fold>

    private void jButton1ActionPerformed(ActionEvent evt) {
        try {
            URL header = new URL(jTextField2.getText());
                jTextArea1.setPage(header);
            }catch(MalformedURLException e){} catch(IOException e){}
        }


        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            header gui = new header();
            gui.initComponents();
        }
        // Variables declaration - do not modify
        private JButton jButton1;
        private JScrollPane jScrollPane1;
        private JEditorPane jTextArea1;
        private JTextField jTextField2;
        private JTextField jTextField3;
        // End of variables declaration
    }

I just havent been able to get it to refresh and display the contents of the same url twice. It loads the contents when I hit the load button but if I hit the load button again it doesnt load the url or display the contents.. What am I doing wrong? I am very new to java so sorry if it is a simple solution, if You could point me in the right direction to solving this issue it would be great, Thanks!

Anuj Balan
  • 7,629
  • 23
  • 58
  • 92
CLUEL3SS
  • 223
  • 1
  • 3
  • 10
  • 2
    As a first debugging step, you should *not* swallow exceptions. Print their stack trace at least – Rom1 Aug 23 '11 at 08:46
  • Yeah I usually do, Im not sure why it didnt put that in this time, and jTextArea1.revalidate(); did not seem to resolve the issue – CLUEL3SS Aug 23 '11 at 08:56
  • please see my answer http://stackoverflow.com/questions/7158854/how-to-load-a-url-to-be-able-to/7159035#7159035 in your 2nd. post – mKorbel Aug 23 '11 at 09:49
  • How do you know that your button does not load the page again? – Angel O'Sphere Aug 23 '11 at 10:24

1 Answers1

1

I vaguely seem to remember that you need to force the editor pane to reload the page.

Just guessing, but you can try:

setContentType("");

or

setDocument(null);
camickr
  • 321,443
  • 19
  • 166
  • 288