[英]Display more than one webpage inside a JFrame
How can I display more than one webpage inside a JFrame
? 如何在
JFrame
显示多个网页?
JEditorPane website = new JEditorPane(line);
website.setEditable(false);
JFrame frame = new JFrame("JxBrowser");
addressBar.setText(line);
frame.add(new JScrollPane(website));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.setVisible(true);
I have put this code inside a for
loop, as usual website are open in different frame, I want all my browser websites to be open inside a single frame, 我已将此代码放在
for
循环中,因为通常的网站在不同的框架中打开,我希望我的所有浏览器网站都在一个框架内打开,
How this is possible? 这怎么可能?
As @JBNizet mentioned in the comments, you could use a JTabbedPane. 正如@JBNizet在评论中提到的,你可以使用JTabbedPane。
Instead of adding the website JEditorPane directly to the JFrame, do this: 而不是将网站JEditorPane直接添加到JFrame,请执行以下操作:
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add("Website Title", new JScrollPane(website));
frame.add(tabbedPane);
Of course, you shouldn't create a new JTabbedPane or new JFrame for each website, instead you should just add the website as a new tab to the already existing tabbed pane. 当然,您不应为每个网站创建新的JTabbedPane或新的JFrame,而只需将网站作为新选项卡添加到现有的选项卡式窗格中。
Don't forget that each tab would require their own addressBar object. 不要忘记每个选项卡都需要自己的addressBar对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.