How to give space in between JList cell.

Posted on 2011-04-21
Last Modified: 2013-11-24
I am using JList to display the list of images  in JList.HORIZONTAL_WRAP. But there the no space between the two images.
How can i give the space between the images in both horizontal and vertical direction . Is there any method to set inter cell space of JList.
Question by:Computer07
    LVL 86

    Expert Comment

    You still need a custom renderer (see last) but you could add a Border to the image
    LVL 92

    Expert Comment

    renderer.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    Author Comment

    hi object,
    I have tried your code,  but when i selects icon, selection color appears in border area also, so when we select next icon , we can feel there is no space between icons.

     cant we make the selection area smaller.
    LVL 92

    Accepted Solution


    renderer.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.white));
    LVL 86

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

    779 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

    18 Experts available now in Live!

    Get 1:1 Help Now