Solved

Resizeing JList

Posted on 1998-08-07
1
493 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 100 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now