Solved

Resizeing JList

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is the latest versions eclipse neon 2 141
what is the difference between "sudo su" and "su - root" 6 106
eclipse argument 14 53
session migration servlets 2 28
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

867 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

16 Experts available now in Live!

Get 1:1 Help Now