Article View: borland.public.jbuilder.java.swing
Article #9365Re: JScrollPane doesn't appear in JPanel
From: Greg Hamer
Date: Tue, 18 Apr 2000 00:00
Date: Tue, 18 Apr 2000 00:00
74 lines
3194 bytes
3194 bytes
I make that mistake all the time. When adding something to a JScrollPane,
you
need to call getViewport().add().
Jeff Marendo <marendoj@commos.com> wrote in message news:38fcd824@dnews...
> Hello,
>
> I'm making an applet that has a JTabbedPane with two tabs. Each tab has a
> JPanel associated with it that uses a BorderLayout and contains a
> JScrollPane in the center location. I have two other JPanels (one for each
> tab) that each have their layouts set to 'null'. These panels have several
> components on them and vary in size (they're named SmallDummyPanel and
> LargeDummyPanel).
>
> Generally, this is what I'm doing: 1. add a panel (e.g. LargeDummyPanel
> instance) to a JScrollPane instance. 2. add that scroll panel to one of
the
> panels that has a border layout. 3. create a tab by adding that panel to
the
> JTabbedPane instance. 4. add that instance to 'this', which is the applet.
>
> The problem is, I'm not seeing the actual vertical and horizontal
scrollbars
> appear for the panel that contains my LargeDummyPanel instance. When I use
> the JScrollPane constants for always showing them, only the corners appear
> with no bars between them. My code is below if anyone can give me some
help.
> Thanks in advance.
>
>
> public class TabbedApplet extends JApplet
>
> JTabbedPane tabPane = new JTabbedPane()
>
> public void paint(Graphics g)
>
> super.paint(g);
> getParent().validate();
> }
> };
> JPanel p1 = new JPanel();
> JPanel p2 = new JPanel();
> SmallDummyPanel sdp = new SmallDummyPanel();
> LargeDummyPanel ldp = new LargeDummyPanel();
> JScrollPane scroll1 = new JScrollPane();
> JScrollPane scroll2 = new JScrollPane
> JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
> JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
> BorderLayout borderLayout1 = new BorderLayout();
> BorderLayout borderLayout2 = new BorderLayout();
> ...
> private void jbInit() throws Exception
>
> this.setSize(new Dimension(500,400));
> p1.setLayout(borderLayout1);
> scroll1.add(sdp);
> p1.add(scroll1, BorderLayout.CENTER);
> tabPane.addTab("Tab 1", p1);
> p2.setLayout(borderLayout2);
> scroll2.add(ldp);
> p2.add(scroll2, BorderLayout.CENTER);
> tabPane.addTab("Tab 2", p2);
> this.getContentPane().add(tabPane, BorderLayout.CENTER);
> }
>
> The other panel sizes are: LargeDummyPanel - (600,400); SmallDummyPanel -
> (400,300). The size, min size and preferred size are all being set with
> those same values, respectively. Also, the size of the frame the applet
> sits in is (500, 420).
>
> jeff
>
>
>
Technical Details
Message-ID:
<8dit9g$q2c2@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38fcd824@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,2517369386e172b3 X-Google-Attributes: gid111d45,public From: "Greg Hamer" <ghamer@corp.netzero.net> Subject: Re: JScrollPane doesn't appear in JPanel Date: 2000/04/18 Message-ID: <8dit9g$q2c2@bornews.borland.com> X-Deja-AN: 612920071 References: <38fcd824@dnews> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.swing