Get Number Of Visible Rows Of AWT List Example
- /*
- Get Number Of Visible Rows Of AWT List Example
- This java example shows how to get number of visible rows of a Java AWT
- List class.
- */
- import java.applet.Applet;
- import java.awt.Graphics;
- import java.awt.List;
- /*
- <applet code="GetNumberOfVisibleRowsExample" width=200 height=200>
- </applet>
- */
- public class GetNumberOfVisibleRowsExample extends Applet{
- List list = null;
- public void init(){
- //create a list
- list = new List(5, true);
- //add items to a list
- list.add("One");
- list.add("Two");
- list.add("Three");
- list.add("Four");
- list.add("Five");
- list.add("Six");
- list.add("Seven");
- //add list
- add(list);
- }
- public void paint(Graphics g){
- /*
- * To get number of visible rows of AWT list, use
- * int getRows()
- * method.
- */
- g.drawString("There are " + list.getRows() + " rows visible", 10, 120);
- }
- }
Example Output




