1

How can I display more than one webpage inside a 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,

How this is possible?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
sam smith
  • 25
  • 1
  • 6
  • 1
    Real browsers typically use tabs, right? And Swing has a JTabbedPane. – JB Nizet Nov 25 '16 at 10:53
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) Note that among the many suggestions for alternatives is (probably the most logical one) as suggested by @JBNizet. – Andrew Thompson Nov 25 '16 at 11:15

1 Answers1

0

As @JBNizet mentioned in the comments, you could use a JTabbedPane.

Instead of adding the website JEditorPane directly to the JFrame, do this:

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.

Don't forget that each tab would require their own addressBar object.

Dramentiaras
  • 193
  • 1
  • 3
  • 12