`
tuxq5721
  • 浏览: 33269 次
社区版块
存档分类
最新评论

Swing —— JList常用API

阅读更多

初始List数据

 

方法或构造器

意义

JList(ListModel)

JList(Object[])

JList(Vector)

JList()

创建一个具有指定的初始列表项的JList,第二个和第三个构造函数隐式地创建一个不可变的ListModel。

void setModel(ListModel)

ListModel getModel()

设置或获取包含内容的模型。

void setListData(Object[])

void setListData(Vector)

设置列表数据项。这些方法隐式地创建一个不可变的ListModel。

 

显示List

 

方法

意义

void setVisibleRowCount(int)

int getVisibleRowCount()

设置或获取visibleRowCount属性,对于垂直(VERTICAL )布局方向,此设置/获取要显示,而无需滚动行的首选行数。对于HORIZONTAL_WRAP或VERTICAL_WRAP布局方向,它定义了单元格如何换行。这个属性的默认值为:VERTICAL。

void setLayoutOrientation(int)

int getLayoutOrientation()

设置或获取列表单元格的布局方式。有HORIZONTAL_WRAP和VERTICAL_WRAP

int getFirstVisibleIndex()

int getLastVisibleIndex()

获得第一个或最后一个可见项目的索引。

void ensureIndexIsVisible(int)

滚动至指定索引,在当前滚动视口(viewport )可见。

 

管理选择信息

 

方法

意义

void addListSelectionListener(ListSelectionListener)

注册以接收选择更改通知的监听器。

void setSelectedIndex(int)

void setSelectedIndices(int[])

void setSelectedValue(Object, boolean)

void setSelectionInterval(int, int)

设置当前所选择。可使用setSelectionMode设置什么选择的范围是可以接受的。

对于第三个方法的布尔参数,用于指定选择项是否应该滚动本身显示在视口(Viewport

int getAnchorSelectionIndex()

int getLeadSelectionIndex()

int getSelectedIndex()

int getMinSelectionIndex()

int getMaxSelectionIndex()

int[] getSelectedIndices()

Object getSelectedValue()

Object[] getSelectedValues()

获取有关表示当前选择的信息。

void setSelectionMode(int)

int getSelectionMode()

设置或获取选择模式。

可接受的值,它们都定义在ListSelectionModel中:

  • SINGLE_SELECTION:单选,一次只能选择一个选项
  • SINGLE_INTERVAL_SELECTION:
  • MULTIPLE_INTERVAL_SELECTION:默认值

void clearSelection()

boolean isSelectionEmpty()

设置或获取是否有任何列表项被选中。

boolean isSelectedIndex(int)

确定指定索引所对应的项是否被选中

 

管理List数据

 

类或方法

意义

int getNextMatch(String, int, javax.swing.text.Position.Bias)

给定开始索引,搜索列表中以指定字符串开头的项,并返回该索引(或-1,如果没有找到字符串)。第三个参数,它指定了搜​​索方向,可以是Position.Bias.Forward或Position.Bias.Backward。例如:如果你有6个项的一个List,那么 getNextMatch("Matisse", 5, javax.swing.text.Position.Bias.Forward) ,则搜索到字符串“Matisse”的项目在索引5,然后(如果需要)在索引0,索引1,依此类推。

void setDragEnabled(boolean)

boolean getDragEnabled()

设置或获取决定自动拖动处理是否已启用的属性。SeeDrag and Drop and Data Transfer for more details.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics