如何在启动后将jBrowser添加到框架中?

时间:2014-05-05 13:36:14

标签: java swing djnativeswing

我有一个Starter类,它运行我的应用程序:

public class Starter {  
    public static Panel createContent() {
          Panel contentPane = new Panel();
          final JWebBrowser webBrowser = new JWebBrowser();
          webBrowser.navigate("http://orientalcraft.org/");
          webBrowser.setBarsVisible(false);   
          webBrowser.setStatusBarVisible(false);  
          contentPane.add(webBrowser);
          return contentPane;

      }

    public static void main(String[] args) throws IOException, Exception
    {
        Frame.go();
        NativeInterface.open();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {

                Frame frame = Frame.mainFrame; //mainFrame - instance of Frame
                frame.getContentPane().add(createContent(), BorderLayout.CENTER);
            }

        });

        NativeInterface.runEventPump();   
    }
}

当我尝试将jBrowser添加到Frame时,我对jBrowser一无所知。但我可以在控制台中看到:

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196)  at java.net.SocketInputStream.read(SocketInputStream.java:196)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
    at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2293)
    at java.io.ObjectInputStream$BlockDataInputStream.peek(ObjectInputStream.java:2586)
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2596)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1318)
    at java.io.ObjectInputStream.readUnshared(ObjectInputStream.java:460)
    at chrriis.dj.nativeswing.swtimpl.core.OutProcessSocketsMessagingInterface.readMessageFromChannel(OutProcessSocketsMessagingInterface.java:116)
    at chrriis.dj.nativeswing.swtimpl.core.MessagingInterface$2.run(MessagingInterface.java:392)

请帮助我向现有jBrowser添加jFrame ..

1 个答案:

答案 0 :(得分:1)

  

请帮我把jBrowser添加到现有的jFrame ..

将组件添加(或删除)到可见GUI时,基本代码为:

panel.add(...);
panel.revalidate();
panel.repaint();

以上是针对Swing的问题,你说它正在使用,但示例代码似乎使用的是Frame而不是JFrame。尝试使用JFrame。或者对于AWT,我认为你会使用validate()