Solved

Resizeing JList

Posted on 1998-08-07
1
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.
Suggested Courses

732 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