我有一个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
..
请帮我添加一个jBrowser到现有的jFrame.
当你添加(或删除)一个组件到一个可见的GUI时,基本代码是:
panel.add(...);
panel.revalidate();
panel.repaint();
上面是你质疑说你正在使用的Swing,但是示例代码似乎使用的是Frame而不是JFrame。尝试使用JFrame。对于AWT,我认为您可以使用validate()
。