🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17093

Vertical Scrolling only in JDK1.1

#17093
From: William Yu
Date: Sun, 20 Dec 1998 00:00
48 lines
2366 bytes
Ok, here's the story.  I want to have to a scrolleable panel but only
scroll in the vertical direction.  Because the default behavior is to
scroll in both directions, layouts like FlowLayout only grow the panel
in the horizontal direction.

So this is approximately what I attempted:

ScrollPane sp = new ScrollPane();
MyPanel p = new MyPanel();
sp.add(p);

//-------------------------------------------------------------------------

public class MyPanel extends Panel {
  public Dimension getPreferredSize() {
    Dimension pref = super.getPreferredSize();
    if (getParent() != null && getParent() instanceof ScrollPane) {
      Dimension parent = ((ScrollPane)getParent()).getViewportSize();
      pref.height = (int)(pref.height * (pref.width / parent.width) *
1.5);
        // HACK RIGHT HERE ^^^
      pref.width = parent.width;
    }
    return pref;
  }

  // INFO ONLY
  public void doLayout() {
    super.doLayout();
    System.out.println(
      "true height = "+
      getComponent(getComponentCount()-1).getLocation().y +
      getComponent(getComponentCount()-1).getSize().height);
  }
}

It works to some degree.  The problem is that I can't calculate the
height correctly.  For example, super.getPreferredSize() might return
(600, 30).  I then change the preferred width to match the viewport
size, say 200.  But this now does not leave enough room to layout the
remaining components that don't fit after (200, 30).  Currently, I'm
using an arbitrary formulate (note the HACK above) to increase the
height but it obviously does not match up with where the last component
is positioned.

If I override the doLayout method, I can calculate what the preferred
height should.  The problem is that doLayout does not execute until
after the layoutmanager requests the preferred size.
Technical Details
Message-ID: <367DDDD7.A42A49CC@Bigfoot.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,6eff78e68a59862e,start
X-Google-Attributes: gidf74b3,public
From: William Yu <William_Yu@Bigfoot.com>
Subject: Vertical Scrolling only in JDK1.1
Date: 1998/12/20
Message-ID: <367DDDD7.A42A49CC@Bigfoot.com>
X-Deja-AN: 424401949
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language