JList: horizontal wrap not working with 5 or more items per row

Discussion in 'Java' started by Scott Steiner, Jul 5, 2005.

  1. Hi,

    I have a JList with a HORIZONTAL_WRAP LayoutOrientation. All is fine but
    when I want to display 5 or more items in a row then the JList only
    displays 4 items in a row and then make a wrap. How can I display 5
    elements in each row? Here is the simple copy & paste code:

    import java.awt.Container;
    import javax.swing.*;

    public class Test extends JFrame
    {
    public Test()
    {
    Container c = this.getContentPane();
    c.setLayout(null);
    this.setSize(200,200);

    DefaultListModel listModel = new DefaultListModel();
    listModel.addElement("1");
    listModel.addElement("2");
    listModel.addElement("3");
    listModel.addElement("4");
    listModel.addElement("5");
    listModel.addElement("6");
    listModel.addElement("7");

    JList sourceList = new JList(listModel);
    sourceList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    sourceList.setBounds(10,10,100,100);

    int rowCount = listModel.getSize() / 5;
    if ((listModel.getSize() % 5) != 0) rowCount += 1;
    sourceList.setVisibleRowCount(rowCount);
    c.add(sourceList);

    this.setVisible(true);
    }

    public static void main(String[] args)
    {
    new Test();
    }
    }
    Scott Steiner, Jul 5, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. paul
    Replies:
    8
    Views:
    638
  2. Replies:
    7
    Views:
    40,084
    rex64
    Oct 29, 2006
  3. Aaron Fude

    To wrap or not to wrap?

    Aaron Fude, May 8, 2008, in forum: Java
    Replies:
    12
    Views:
    686
    Chronic Philharmonic
    May 10, 2008
  4. Art Werschulz

    Text::Wrap::wrap difference

    Art Werschulz, Sep 22, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    221
    Art Werschulz
    Sep 22, 2003
  5. Art Werschulz

    Text::Wrap::wrap difference

    Art Werschulz, Sep 24, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    233
    Anno Siegel
    Sep 25, 2003
Loading...

Share This Page