jkflist.java
来自「主要是对串口驱动的的一些控制源码!!! 在下载javacomm20-win32」· Java 代码 · 共 129 行
JAVA
129 行
/*
* $Log: JKFList.java,v $
* Revision 1.4 2003/01/23 14:40:55 willaxt
* changed semantics of setData()
*
* Revision 1.3 2003/01/23 14:34:21 willaxt
* changed source comments
*
* Revision 1.2 2003/01/23 14:07:29 willaxt
* changed javadoc comment
*
* Revision 1.1 2003/01/23 14:00:16 willaxt
* initial version
*
*/
package de.fhm.jkf.gui;
import java.util.Vector;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JList;
import javax.swing.ListModel;
/**
* <br><br><center><table border="1" width="80%"><hr>
* <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
* <p>
* Copyright (C) 2002 by Theodor Willax
* <p>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* <p>
* You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
* GNU Lesser General Public License</a> along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
* <hr></table></center>
*
* JKF implementation of a <code>JList</code>. Implements the
* <code>DataExchangable</code> interface for automatic data exchange.
*
* @author Theodor Willax
* @version $Revision: 1.4 $
*/
public class JKFList extends JList implements DataExchangable {
/**
* Constructs a <code>JKFList</code> that displays the
* elements in the specified, non-<code>null</code> model.
*/
public JKFList(ListModel dataModel) {
super(dataModel);
}
/**
* Constructs a <code>JKFList</code> that displays the elements in the
* specified array.
*/
public JKFList(Object[] listData) {
super(listData);
}
/**
*Constructs a <code>JKFList</code> that displays the elements in the
* specified <code>Vector</code> .
*/
public JKFList(Vector listData) {
super(listData);
}
/**
* Constructs a <code>JKFList</code> with an empty model.
*/
public JKFList() {
super();
}
/**
* Set's the lists selected items. Data has to be given in a
* <code>Vector</code>.
*
* @param data The data to be selected, wrapped in a
* <code>Vector</code>.
* @see de.fhm.jkf.gui.DataExchangable#setData(Object)
*/
public void setData(Object data) {
clearSelection();
Vector v = (Vector) data;
int size = v.size() - 1;
for (int i=0; i < size; i++) {
setSelectedValue(v.get(i), false);
}
// scroll only to the last element, scrolling for each would be to slow
setSelectedValue(v.lastElement(), true);
}
/**
* Returns the lists selected data. In single selection mode,
* only one data object in a <code>Vector</code> is returned.
* If multiple selections are allowed, the selected values are
* all put into an <code>Vector</code> and returned.
*
* @return Object The lists selected data in a <code>Vector</code>
* @see de.fhm.jkf.gui.DataExchangable#getData()
*/
public Object getData() {
// are we in single selection mode
if (getSelectionMode() == DefaultListSelectionModel.SINGLE_SELECTION) {
Vector v = new Vector(1);
v.add(getSelectedValue());
return v;
} else {
Object o[] = getSelectedValues();
Vector v = new Vector(o.length);
for (int i=0; i < o.length; i++) {
v.add(o[i]);
}
return v;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?