Article View: borland.public.jbuilder.java.swing
Article #12755Re: JList size in a JScrollPane?
From: Dave Howorth
Date: Fri, 13 Nov 1998 00:00
Date: Fri, 13 Nov 1998 00:00
68 lines
2688 bytes
2688 bytes
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?
Technical Details
Message-ID:
<72fu3o$d5n28@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<727hon$ov14@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: "Dave Howorth" <5bx@iname.com> Subject: Re: JList size in a JScrollPane? Date: 1998/11/13 Message-ID: <72fu3o$d5n28@forums.borland.com> X-Deja-AN: 411271919 References: <727hon$ov14@forums.borland.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3 Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing