Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Resizeing JList

Posted on 1998-08-07
1
Medium Priority
?
506 Views
Last Modified: 2011-10-03
I would like to create a JList that fills a window (with vertical and horizontal scroll bars if necessary) and have that JList expand or contract if the window is resized. How can I do that?
0
Comment
Question by:jc31415
1 Comment
 
LVL 5

Accepted Solution

by:
fontaine earned 400 total points
ID: 1231772
You need to embed the JList in a JScrollPane to have the scroll bars (several policies are
available, check the doc. for that). To have it fill the entire area, you can use the GridLayout
layout manager. Here is an example:

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


public class Test extends JFrame {

    public Test() {
        String[] data = {"oneaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "two", "free", "four", "one", "two", "free", "four"};
        JList dataList = new JList(data);
        JScrollPane scroll = new JScrollPane(dataList);

        Container c = getContentPane();
        c.setLayout(new GridLayout());
        c.add(scroll);
    }

    public static void main(String args[]) {
        Test t = new Test();
        t.pack();
        t.show();
        return;
    }
   
}
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question