如何在 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);
我已将此代码放入 for
循环中,就像通常的网站在不同的框架中打开一样,我希望所有浏览器网站都在单个框架中打开,
这怎么可能?
最佳答案
正如 @JBNizet 在评论中提到的,您可以使用 JTabbedPane。
不要将网站 JEditorPane 直接添加到 JFrame,而是执行以下操作:
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add("Website Title", new JScrollPane(website));
frame.add(tabbedPane);
当然,您不应该为每个网站创建新的 JTabbedPane 或新的 JFrame,而应该将网站作为新选项卡添加到现有的选项卡式 Pane 中。
不要忘记每个选项卡都需要自己的地址栏对象。
关于java - 在 JFrame 中显示多个网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40803230/