0

我有一个 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..

4

1 回答 1

1

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

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

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

以上是针对您所使用的 Swing,但示例代码似乎使用的是 Frame 而不是 JFrame。尝试使用 JFrame。或者对于 AWT,我认为您会使用validate().

于 2014-05-05T14:44:41.760 回答