我想显示数据库中的数据。javaFx 1.3 中没有 TableView,所以我使用了 ListView。但是,当我将文本框放在列表视图中时,它表现不佳。我在获取数据时遇到问题。谁能给我一个带有文本框的listview代码,它还可以获取和更新数据。
问问题
116 次
1 回答
1
var lv_dept_nm:String = "";
var lv_dept_des:String = "";
var lv_dept_name:TextBox;
var lv_dept_desc:TextBox;
var lv_dept_upBtn: Button;
var lv_dept_flag:Boolean = false;
var lv_dept_ind: Integer;
var lv_dept_len: Integer = 0;
var lv_dept_size:Integer = 0;
function removeLastChar(str: String)
{
var string;
if(str != "")
{
string = str.substring(0, str.length()-1);
}
else
{
string = str;
}
return string;
}
var viewDepartmentListView: ListView = ListView
{
items: bind [dept_choicebox_item]
layoutInfo: LayoutInfo{height:bind lv_dept_size}
layoutX: 170
layoutY: 150
width: 500
cellFactory: function() {
var listCell: ListCell;
if(dept_choicebox_item.size() > 5)
{
lv_dept_size = 55 * 5;
}
else
{
lv_dept_size = 55 * dept_choicebox_item.size();
}
listCell = ListCell {
node : HBox {
width: 200
content: [
VBox {
spacing: 10
content: [
Label {
text: bind dept_choicebox_item[listCell.index]
visible: bind not listCell.empty and not lv_dept_flag or not listCell.selected or (lv_dept_ind != listCell.index)
}
lv_dept_name = TextBox
{
promptText: bind dept_choicebox_item[listCell.index]
onKeyPressed: function(ke: KeyEvent)
{
if(ke.code.toString() == "VK_BACK_SPACE")
{
lv_dept_len = lv_dept_nm.length();
lv_dept_nm = removeLastChar(lv_dept_nm);
}
}
onKeyTyped: function(e:KeyEvent)
{
if(lv_dept_len != 0)
{
lv_dept_len = 0;
}
else if(lv_dept_nm == "")
{
lv_dept_nm = e.char;
}
else
{
lv_dept_nm = '{lv_dept_nm}{e.char}';
}
}
columns: 12
visible:bind not listCell.empty and lv_dept_flag and listCell.selected and (lv_dept_ind == listCell.index)
}
]
}
VBox {
spacing: 10
content: [
Label {
text: bind description[listCell.index]
visible: bind not listCell.empty and not lv_dept_flag or not listCell.selected or (lv_dept_ind != listCell.index)
}
lv_dept_desc = TextBox
{
promptText: bind description[listCell.index]
onKeyPressed: function(ke: KeyEvent)
{
if(ke.code.toString() == "VK_BACK_SPACE")
{
lv_dept_len = lv_dept_des.length();
lv_dept_des = removeLastChar(lv_dept_des);
}
}
onKeyTyped : function(e: KeyEvent)
{
if(lv_dept_len != 0)
{
lv_dept_len = 0;
}
else if(lv_dept_des == "")
{
lv_dept_des = e.char;
}
else
{
lv_dept_des = '{lv_dept_des}{e.char}';
}
}
columns: 12
visible:bind not listCell.empty and lv_dept_flag and listCell.selected and (lv_dept_ind == listCell.index)
}
]
}
VBox{
spacing: 10
content: [
Button {
vpos: VPos.TOP;
text: "Edit"
visible: bind not listCell.empty and (not lv_dept_flag or not listCell.selected or (lv_dept_ind != listCell.index))
action: function() {
lv_dept_ind = listCell.index;
lv_dept_flag = true;
}
}
lv_dept_upBtn = Button {
vpos: VPos.TOP;
text: "Update"
visible: bind not listCell.empty and lv_dept_flag and listCell.selected and (lv_dept_ind == listCell.index)
action: function() {
cs = cn.prepareCall("call update_dept(?,?,?)");
cs.setString(1, '{dept_choicebox_item[listCell.index]}');
cs.setString(2, '{lv_dept_nm}');
cs.setString(3, '{lv_dept_des}');
cs.executeUpdate();
dept_choicebox_item[listCell.index] = lv_dept_nm;
description[listCell.index] = lv_dept_des;
lv_dept_flag = false;
lv_dept_nm = "";
lv_dept_des = "";
}
}
]
}
VBox{
spacing: 10
content: [
Button {
vpos: VPos.TOP;
text: "Delete"
visible: bind not listCell.empty and (not lv_dept_flag or not listCell.selected or (lv_dept_ind != listCell.index))
action: function() {
cs = cn.prepareCall("call delete_dept(?)");
cs.setString(1,'{dept_choicebox_item[listCell.index]}');
cs.executeUpdate();
delete dept_choicebox_item[listCell.index] from dept_choicebox_item;
delete description[listCell.index] from description;
lv_dept_size = 55 * dept_choicebox_item.size();
}
}
]
}
]
}
}
}
visible:true;
};
于 2013-04-07T03:23:49.847 回答