Example usage for javax.swing JList setVisibleRowCount

List of usage examples for javax.swing JList setVisibleRowCount

Introduction

In this page you can find the example usage for javax.swing JList setVisibleRowCount.

Prototype

@BeanProperty(visualUpdate = true, description = "The preferred number of rows to display without requiring scrolling")
public void setVisibleRowCount(int visibleRowCount) 

Source Link

Document

Sets the visibleRowCount property, which has different meanings depending on the layout orientation: For a VERTICAL layout orientation, this sets the preferred number of rows to display without requiring scrolling; for other orientations, it affects the wrapping of cells.

Usage

From source file:Main.java

public static void main(String[] args) {
    int bigNumber = 30001;
    String[] bigData = new String[bigNumber];
    for (int ii = 0; ii < bigNumber; ii++) {
        bigData[ii] = "String " + (ii + 1);
    }/*ww w.  ja v a 2s . c  om*/
    JList list = new JList(bigData);
    list.setVisibleRowCount(5);

    JOptionPane.showMessageDialog(null, new JScrollPane(list));
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList(labels);
    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    frame.setSize(300, 350);//  w  w  w . j av a 2s .c  o  m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList(labels);
    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.setValueIsAdjusting(false);//from  w w w  .  ja  va 2s . c  o m

    frame.setSize(300, 350);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList(labels);
    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.setSelectedIndices(new int[] { 1, 2 });

    frame.setSize(300, 350);//from   w  w w .  j a v  a2  s.  c  o  m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList(labels);
    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.setSelectionForeground(Color.RED);

    frame.setSize(300, 350);//  w w w.  j a  v a 2 s.  c  o m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList(labels);
    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    frame.setSize(300, 350);/*  w  w  w. jav  a 2  s.c o m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList(labels);
    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.setSelectedIndex(1);/*from   w w w.j a va 2 s  .  com*/

    frame.setSize(300, 350);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList(labels);
    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.setSelectionBackground(Color.RED);

    frame.setSize(300, 350);// w w  w . j a  v  a2s.  co  m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Vector<String> data = new Vector<String>();
    for (int i = 1; i < 100; i++) {
        data.add("Entry " + i);
    }//from  www  .  ja  v a 2 s.  c  o  m
    JList<String> list = new JList<>(data);
    list.setVisibleRowCount(8);
    JScrollPane scrollPane = new JScrollPane(list);
    frame.add(scrollPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(1000);/*  ww  w  . ja v  a 2 s. c o  m*/
    for (int j = 0; j < 5; j++) {
        model.addElement(labels[j]);
    }
    model.trimToSize();

    JList jlist2 = new JList(model);
    jlist2.setVisibleRowCount(4);
    jlist2.setFixedCellHeight(12);
    jlist2.setFixedCellWidth(200);
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

    frame.setSize(300, 350);
    frame.setVisible(true);
}