Java Swing Tutorial - Java JList.getLayoutOrientation()








Syntax

JList.getLayoutOrientation() has the following syntax.

public int getLayoutOrientation()

Example

In the following code shows how to use JList.getLayoutOrientation() method.

//from  w  ww . j  a v a 2s .c o  m

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

public class Main {
  public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);
    JScrollPane scrollingList = new JScrollPane(list);

    // The default layout orientation is JList.VERTICAL
    int orient = list.getLayoutOrientation();

    // Change the layout orientation to left-to-right, top-to-bottom
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
  }
}