Java Swing Tutorial - Java JList.getCellBounds(int index0, int index1)








Syntax

JList.getCellBounds(int index0, int index1) has the following syntax.

public Rectangle getCellBounds(int index0,   int index1)

Example

In the following code shows how to use JList.getCellBounds(int index0, int index1) method.

//from   w ww.j a  va2s  .  c  om
import java.awt.BorderLayout;
import java.awt.Rectangle;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class Main {

  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();
    jlist1.setListData(labels);
    
    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);
    
    Rectangle r  = jlist1.getCellBounds(0, 1);
    
    frame.setSize(300, 350);
    frame.setVisible(true);
  }
}