🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #13252

Re: JList with scrollbar

#13252
From: zimmerer
Date: Wed, 26 Aug 1998 00:00
73 lines
2372 bytes
It does not work there still is no scrollbar. I've wrote a little test code,
perhaps someone can take a short look at it and tell me whats wrong.

import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Test extends JFrame {

  public Test() {
    Frame1 frame = new Frame1();
    frame.setVisible(true);
  }
  public static void main(String[] args) {
    new Test();
  }

  class Frame1 extends JFrame {
    GridLayout grid = new GridLayout();
    public Frame1() {
      this.getContentPane().setLayout(grid);
      this.setSize(200,200);
      DefaultListModel model = new DefaultListModel();
      JList list = new JList(model);
      JScrollPane scroll = new JScrollPane();
      scroll.getViewport().setView(list);
      //this doesn't work, too
      //JList list =new JList(model);
      //JScrollPane scroll = new JScrollPane(list);
      this.getContentPane().add(list);
      for (int i=0;i<20;i++) {
        model.addElement("item"+i);
      }
    }
    protected void processWindowEvent(WindowEvent e) {
      super.processWindowEvent(e);
      if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        System.exit(0);
      }
    }
  }
}


Martin Anders wrote:

> Hi,
>
> try this:
>
> Jlist list = new JList();
> JScrollPane scroll = new JScrollPane();
> scroll.getViewport().setView(list);
>
> that should work.
>
> Martin
>
> zimmerer wrote:
>
> > Does anybody out there knows how to add a scrollbar to a JList??
> > I've tried the follow:
> >
> > JList list = new JList();
> > JScrollPane scroll = new JScrollPane(list);
> >
> > .......nothing happens, no scrollbar at all even I've added 1000 items
> > to the box.
> > Can anyone HELP me!
> >
> > thx.
> >
> > alex
Technical Details
Message-ID: <35E3D07E.FA559753@cimag.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35E2A7B4.B5EC3479@cimag.de> <35E2F53B.2269C0AA@csi.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,b5ee876fbd119f83
X-Google-Attributes: gid111d45,public
From: zimmerer <a.zimmerer@cimag.de>
Subject: Re: JList with scrollbar
Date: 1998/08/26
Message-ID: <35E3D07E.FA559753@cimag.de>
X-Deja-AN: 384860812
Content-Transfer-Encoding: 7bit
References: <35E2A7B4.B5EC3479@cimag.de> <35E2F53B.2269C0AA@csi.com>
To: Martin Anders <MartinAnders@csi.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing