javaFX

**1.CheckBox**

a.声明:CheckBox checkBox = new CheckBox("choice one");

b.选中:checkBox.isSelected();

**2.ChoiceBox**

a.声明 : ChoiceBox<String> choiceBox = new ChoiceBox<>();

b.添加内容 : choiceBox.getItems().add("XXX")

c.设置初始内容:choiceBox.setValue("XXX");[XXX必须是已经添加的内容]

d.监听内容是否发生改变:choiceBox.getSelectionModel().selectedItemProterty().addListener((v, oldValue, newValue)->System.out.println(newValue));

**3.ComboBox**

a.声明 : ComboBox<String> comboBox = new ComboBox<>();

b.添加内容:comboBox.getItems().add("XXX");

c.获得内容:comboBox.getValue();

d.可编辑:comboBox.setEditable(true);

输入完内容后要按回车键]

**4.ListView**

a.声明:ListView<String> listView = new ListView<>();

b.添加内容:listView.getItems().add("XXX");

c.设置选择模式:listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

d.获得选择内容:ObservableList<String> XXX=listView.getSelectionModel().getSelectedItems();

**5.TreeView**

a.声明:TreeView<String> treeView = new TreeView<>(root);

[这里的root一定要填,类型为TreeItem<String>All trees need a root!!!]

b.一开始没有一个展开箭头:treeView.setShowRoot(false);

c.TreeItem:TreeItem<String> root = new TreeItem<>("XXX");

[XXX为显示出来的文字]

一开始为展开状态:root.setExpanded(true);makeBranch("A",root);

private TreeItem<String> makeBranch(String title,TreeItem<String> parent){ TreeItem<String> item = new TreeItem<String>(title);

item.setExpanded(true);

parent.getChildren().add(item); r

eturn item;

}

**6.TableView**

新建一个product类封装数据,有getter和setter方法

a.声明:TableView<Product> tableView =new TableView<>();

b.在tableview里添加数据:

private ObservableList<Product> getProduct(){

ObservableList<Product> products= FXCollections.observableArrayList();

products.add(new Product("laptop" , 200.00 , 10));

products.add(new Product("corn" , 1.49 ,100));

products.add(new Product("tolite" ,99.98 ,74));

return products;

}

tableView.getItems(getProduct());

c.设置表里的栏声明:

TableColumn<Product,String> nameColumn = new TableColumn<>("Name");

[Product是数据来源的类,String是数据类型,"Name"是栏的名称]

数据:nameColumn.setCellValueFactory(new PropertyValueFactory<>("Name"));

设置最小宽度:nameColumn.setMinWidth(100);

将添加到表中:table.getColumns().add(nameColumn);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值