?
Solved

Resizeing JList

Posted on 1998-08-07
1
Medium Priority
?
503 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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