Wednesday, April 1, 2009

Friday April 3: Java Swing Tabbed Browsing, part Four

Some of the sharper elements here may have noticed: hey, some websites are CUT OFF! I can't reach the bottom of the page! Wazzup wi' THAT?


Well, its true, a JeditorPane by itself will not scroll down to see all the stuff on a webpage that's too big to fit...that's why you need a "JScrollPane". What we will do is to put the JEditorPane which holds your webpage inside a JScrollPane which is added to the JTabbedPane which is added to a Container which is added to a JFrame.


Holy crap..supply lines are getting longer and harder to maintain!


Add this to your declarations
JScrollPane scrollTheWeb; //to make webpages scroll

Add this to the “try catch” in the method makeTab( ),

//put webpage container inside scroller
scrollTheWeb = new JScrollPane(newWeb);
scrollTheWeb.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

Just below where you have this line:
newWeb.setBounds(10,50,850,720);

and then change this line
Tabitha.add("Page " + pageNumber , newWeb);

To look like this
Tabitha.add("Page " + pageNumber , scrollTheWeb);

Shazzam!
Uncle Paulie

No comments:

Post a Comment