Article View: borland.public.jbuilder.java.swing
Article #12758Re: JList size in a JScrollPane?
From: annmo
Date: Fri, 13 Nov 1998 00:00
Date: Fri, 13 Nov 1998 00:00
90 lines
3607 bytes
3607 bytes
Hi,
I don't think I can explain, but I've had some trouble with a scrolling
JList and finally got it to work. I suggest that you replace "the problem"-
row with something like:
jList.setVisibleRowCount(8);
jList.setFixedCellWidth(200);
I also had to place the JScrollPane inside a standard JPanel (with
default FlowLayout) to get it size correctly.
Regards
Erik Annmo
In article <72fu3o$d5n28@forums.borland.com>,
"Dave Howorth" <5bx@iname.com> wrote:
> I wrote:
> >(1) When I make the dialog taller (as a user, dragging it at runtime), the
> >list [I assume] expands, adding white space after the end of the list. This
> >is fine. But when I then make the dialog box slightly shorter, a scroll bar
> >is added and I can scroll to a completely blank area. What should happen,
> >IMHO, is for the JList to remove the blank space and just become
> 'naturally'
> >shorter, still with no scroll bar. What am I missing?
>
> I've got a little further with this, and I attach some simple source below
> that demonstrates the problem. It doesn't seem to matter what the window
> type is, nor what layout manager is used. A standard JB app shell creates a
> MyFrame. If the line marked /* THE PROBLEM */ is commented out, it runs OK;
> with it in, it shows the problem above.
>
> Can anybody explain this to me, please?
>
> Thanks, Dave
>
> package ListTests;
>
> import java.awt.*;
> import java.awt.event.*;
> import com.sun.java.swing.*;
>
> public class MyFrame extends JFrame
> {
> //Construct the frame
> JList jList = new JList(new String[] {"one", "two", "three"});
> JScrollPane jScrollPane = new JScrollPane();
>
> public MyFrame()
> {
> enableEvents(AWTEvent.WINDOW_EVENT_MASK);
> try
> {
> jbInit();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }
>
> //Component initialization
> private void jbInit() throws Exception
> {
> jList.setPreferredSize(new Dimension(50, 50)); /* THE PROBLEM */
> jScrollPane.getViewport().add(jList, null);
> this.getContentPane().add(jScrollPane, null);
> }
>
> //Overriden so we can exit on System Close
> protected void processWindowEvent(WindowEvent e)
> {
> super.processWindowEvent(e);
> if (e.getID() == WindowEvent.WINDOW_CLOSING)
> System.exit(0);
> }
> }
>
> /*****************/
>
> PS I went to the bookshop yesterday and looked at the O'Reilly Java Swing
> book. Naturally, I looked at their first JList example and spotted a bug
> (they didn't bind the model to the view). Didn't inspire much confidence in
> the book :-( Are there any better ones?
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Technical Details
Message-ID:
<72h3h3$r6r$1@nnrp1.dejanews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<727hon$ov14@forums.borland.com> <72fu3o$d5n28@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,1177ab7a6295220d X-Google-Attributes: gid111d45,public From: annmo@my-dejanews.com Subject: Re: JList size in a JScrollPane? Date: 1998/11/13 Message-ID: <72h3h3$r6r$1@nnrp1.dejanews.com> X-Deja-AN: 411402883 References: <727hon$ov14@forums.borland.com> <72fu3o$d5n28@forums.borland.com> X-Http-Proxy: 1.0 x1.dejanews.com:80 (Squid/1.1.22) for client 195.67.206.72 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Fri Nov 13 11:00:51 1998 GMT Newsgroups: borland.public.jbuilder.java.swing X-Http-User-Agent: Mozilla/4.04 [en] (WinNT; I)