<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.Scene?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.collections.FXCollections?>
<?import addressbook.*?> <Scene xmlns:fx="http://javafx.com/fxml" fx:controller="addressbook.Controller"
stylesheets="addressbook/addressbook.css">
<GridPane styleClass="grid-pane">
<Label id="address-book" text="%addressBook"
GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<TableView fx:id="tableView" tableMenuButtonVisible="true"
GridPane.columnIndex="0" GridPane.rowIndex="1">
<columns>
<TableColumn fx:id="firstNameColumn"
text="%firstName" prefWidth="100">
<cellValueFactory>
<PropertyValueFactory property="firstName"/>
</cellValueFactory>
<cellFactory>
<FormattedTableCellFactory alignment="CENTER"
addRowContextMenu="true"/>
</cellFactory>
</TableColumn>
<TableColumn
text="%lastName" prefWidth="100">
<cellValueFactory>
<PropertyValueFactory property="lastName"/>
</cellValueFactory>
</TableColumn>
<TableColumn
text="%email" prefWidth="210" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="email"/>
</cellValueFactory>
</TableColumn>
</columns>
<Person firstName="Jacob" lastName="Smith"
email="jacob.smith@example.com"/>
<Person firstName="Isabella" lastName="Johnson"
email="isabella.johnson@example.com"/>
<Person firstName="Ethan" lastName="Williams"
email="ethan.williams@example.com"/>
<Person firstName="Emma" lastName="Jones"
email="emma.jones@example.com"/>
<Person firstName="Michael" lastName="Brown"
email="michael.brown@example.com"/>
<sortOrder>
<fx:reference source="firstNameColumn"/>
</sortOrder>
</TableView>
<HBox styleClass="h-box" GridPane.columnIndex="0" GridPane.rowIndex="2">
<TextField fx:id="firstNameField" promptText="%firstName"
prefWidth="90"/>
<TextField fx:id="lastNameField" promptText="%lastName"
prefWidth="90"/>
<TextField fx:id="emailField" promptText="%email"
prefWidth="150"/>
<Button text="%add" onAction="#addPerson"/>
</HBox>
</GridPane>
</Scene>
/**
* An address book application.
*
* @author HAN
*/
package addressbook;
# Title of window
title=FXML Address Book # Name of label above the table view
addressBook=Address Book # Name of the first table column
# & Prompt text of text field for the first table column
firstName=First Name # Name of the second table column
# & Prompt text of text field for the second table column
lastName=Last Name # Name of the third table column
# & Prompt text of text field for the third table column
email=Email Address # Name of button for adding rows to table
add=Add
# Title of window
title=FXML\u5730\u5740\u7C3F # Name of label above the table view
addressBook=\u5730\u5740\u7C3F # Name of the first table column
# & Prompt text of text field for the first table column
firstName=\u540D\u5B57 # Name of the second table column
# & Prompt text of text field for the second table column
lastName=\u59D3 # Name of the third table column
# & Prompt text of text field for the third table column
email=\u7535\u5B50\u90AE\u4EF6 # Name of button for adding rows to table
add=\u6DFB\u52A0
.grid-pane {
-fx-alignment: center;
-fx-hgap: 10;
-fx-vgap: 10;
-fx-padding: 10;
} #address-book {
-fx-font: NORMAL 20 Tahoma;
} .h-box {
-fx-spacing:10;
-fx-alignment: bottom-right;
}
package addressbook;

import java.text.Format;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.text.TextAlignment;
import javafx.util.Callback; public class FormattedTableCellFactory<S, T> implements
Callback<TableColumn<S, T>, TableCell<S, T>> {
/**
* The alignment for both the multiline text and label position within cell.
*/
private TextAlignment alignment; /**
* Specify a Format if required to format the cell item.
*/
private Format format; /**
* This variable is set because normally only one time of adding context
* menu to table row is needed. So be aware of cooccurrence when setting
* cell factory for multiple columns.
*/
private boolean addRowContextMenu; public TextAlignment getAlignment() {
return alignment;
} public Format getFormat() {
return format;
} public boolean getAddRowContextMenu() {
return addRowContextMenu;
} public void setAlignment(TextAlignment alignment) {
this.alignment = alignment;
} public void setFormat(Format format) {
this.format = format;
} public void setAddRowContextMenu(boolean addRowContextMenu) {
this.addRowContextMenu = addRowContextMenu;
} @Override
public TableCell<S, T> call(TableColumn<S, T> arg0) {
final TableCell<S, T> cell = new TableCell<S, T>() {
@Override
protected void updateItem(T item, boolean empty) {
if (item == getItem()) {
return;
}
super.updateItem(item, empty);
if (item == null) {
setText(null);
setGraphic(null);
} else if (item instanceof Node) {
setText(null);
setGraphic((Node) item);
} else if (format != null) {
setText(format.format(item));
setGraphic(null);
} else {
setText(item.toString());
setGraphic(null);
} if (addRowContextMenu)
addCM(this);
}
};
if (alignment == null)
alignment = TextAlignment.LEFT;
cell.setTextAlignment(alignment);
switch (alignment) {
case CENTER:
cell.setAlignment(Pos.CENTER);
break;
case RIGHT:
cell.setAlignment(Pos.CENTER_RIGHT);
break;
default:
cell.setAlignment(Pos.CENTER_LEFT);
}
return cell;
} private MenuItem delete = new MenuItem("Delete");
private ContextMenu contextMenu = new ContextMenu(delete); private void addCM(final TableCell<S, T> cell) {
@SuppressWarnings("rawtypes")
final TableRow row = cell.getTableRow();
delete.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
cell.getTableView().getItems().remove(row.getItem());
}
});
if (row != null) {
if (row.getItem() != null) {
row.setContextMenu(contextMenu);
}
}
}
}
package addressbook;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; /**
* A Bean convention based data model.
*
* @author HAN
*/
public class Person {
private StringProperty firstName = new SimpleStringProperty();
private StringProperty lastName = new SimpleStringProperty();
private StringProperty email = new SimpleStringProperty(); public Person() {
this("", "", "");
} public Person(String firstName, String lastName, String email) {
setFirstName(firstName);
setLastName(lastName);
setEmail(email);
} public final String getFirstName() {
return firstName.get();
} public final String getLastName() {
return lastName.get();
} public final String getEmail() {
return email.get();
} public final void setFirstName(String firstName) {
this.firstName.set(firstName);
} public final void setLastName(String lastName) {
this.lastName.set(lastName);
} public final void setEmail(String email) {
this.email.set(email);
} public StringProperty firstNameProperty() {
return firstName;
} public StringProperty lastNameProperty() {
return lastName;
} public StringProperty emailProperty() {
return email;
}
}
package addressbook;

import javafx.fxml.FXML;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField; public class Controller {
@FXML
private TableView<Person> tableView;
@FXML
private TextField firstNameField;
@FXML
private TextField lastNameField;
@FXML
private TextField emailField; @FXML
private void addPerson() {
tableView.getItems().add(
new Person(firstNameField.getText(), lastNameField.getText(),
emailField.getText()));
firstNameField.clear();
lastNameField.clear();
emailField.clear();
}
}
package addressbook;

import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle; import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage; public class Model extends Application {
public static void main(String[] args) {
launch(args);
} @Override
public void start(Stage stage) throws Exception {
Locale locale = getCurrentLocale();
ResourceBundle resources = ResourceBundle
.getBundle("addressbook/addressbook", locale,
Model.class.getClassLoader());
stage.setTitle(resources.getString("title"));
stage.setScene((Scene) FXMLLoader.load(
Model.class.getResource("View.fxml"), resources));
stage.show();
} private Locale getCurrentLocale() {
Map<String, String> namedParams = getParameters().getNamed();
String languageParam = namedParams.get("language");
String countryParam = namedParams.get("country"); Locale locale = Locale.getDefault();
if (languageParam != null && languageParam.trim().length() > 0) {
if (countryParam != null && countryParam.trim().length() > 0) {
locale = new Locale(languageParam.trim(), countryParam.trim());
} else {
locale = new Locale(languageParam.trim());
}
}
return locale;
}
}




Address Book(地址薄)的更多相关文章

  1. iOS:访问地址薄

    地址簿的访问 介绍: 地址簿(Address Book)是一个共享的联系人信息数据库.任何iOS应用程序都可以使用.通过提供常用联系人信息,而不是让每一个应用程序管理独立的联系人列表,可改善用户体验. ...

  2. Qt 地址薄 (一) 界面设计

    实现一个简单的地址薄,功能包括:地址的添加.浏览.编辑.查找.输出文件等. 1  界面和元素 整个地址薄界面,可视为一个 AddressBook 类.其中的 Name.Address 以及两个编辑栏, ...

  3. Qt 地址薄 (二) 添加地址

    在上一篇 Qt 地址薄 (一) 界面设计 中,主要是实现了地址簿的界面,使用布局管理器进行元素的布局,并解释了"子类化" 和"所有权"的概念. 本篇将在上面的基 ...

  4. wex5 实战 省市县三级联动与地址薄同步

    无论是商城,还是快递,都要用到省市县三级联动,和地址薄,今天就以实战来制作,难点有3个: 1:三级联动,有wex5组件实现,相对简单,实战里对行数据进行了拼接 2:  地址薄选项,利用inputSel ...

  5. ios开发——实用技术篇Swift篇&地址薄、短信、邮件

    //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnimated(tru ...

  6. python 教程 第十四章、 地址薄作业

    第十四章. 地址薄作业 #A Byte of Python #!/usr/bin/env python import cPickle import os #define the contacts fi ...

  7. 如何从OA系统批量整理出邮箱地址,并导入到Foxmail 地址薄中?

    一.打开某位leader的OA,点击查看“下属” a. 将所有的下属信息 --- 全选 --- 复制 --- 粘贴到 excel 表格中 b. 分别提取“姓名” 和 “邮箱”地址信息,结合notepa ...

  8. LeetCode 1108. Defanging an IP Address (IP 地址无效化)

    题目标签:String 题目给了我们一组 ip address,让我们把 . 变成 [.],这题可以用replace,但是这样做的话,好像没意义了.所以还是走一下array,具体看code. Java ...

  9. <address>标签,为网页加入地址信息

    一般网页中会有一些网站的联系地址信息需要在网页中展示出来,这些联系地址信息如公司的地址就可以<address>标签.也可以定义一个地址(比如电子邮件地址).签名或者文档的作者身份. 语法: ...

随机推荐

  1. (转)苹果推送通知服务教程 Apple Push Notification Services Tutorial

    本文译自http://www.raywenderlich.com/.原文由iOS教程团队 Matthijs Hollemans 撰写,经原网站管理员授权本博翻译. 在iOS系统,考虑到手机电池电量,应 ...

  2. 我的SD卡乱码解决方案

    转载请注明出处.chendesheng1988是原作者. 问题描述:射频模块读取证件信息后,串口读取的信息存到SD卡,存进去发现汉字是乱码. 解决方案:使用函数WideCharToMultiByte搞 ...

  3. 你需要知道的九大排序算法【Python实现】之基数排序

    八.基数排序 基本思想:基数排序(radix sort)属于"分配式排序"(distribution sort),又称"桶子法"(bucket sort)或bi ...

  4. TortoiseGit和msysGit安装及使用笔记(windows下使用上传数据到GitHub)[转]

    TortoiseGit和msysGit安装及使用笔记(windows下使用上传数据到GitHub) Git-1.7.11-preview+GitExtensions244SetupComplete+T ...

  5. PHP页面之间跳转方法总结

    编程中,在页面之间进行跳转是必须的.这里列出了三种办法,供参考. 一.用HTTP头信息 也就是用PHP的HEADER函数.PHP里的HEADER函数的作用就是向浏览器发出由HTTP协议规定的本来应该通 ...

  6. smbpasswd命令常用选项

    smbpasswd命令的常用方法 smbpasswd -a 增加用户(该账户必须存在于/etc/passwd文件中)smbpasswd -d 冻结用户,就是这个用户不能在登录了smbpasswd -e ...

  7. Web应用程序项目XXXX已配置为使用IIS。无法访问IIS元数据库。您没有足够的特权访问计算机上的IIS网站

    问题:Windows8下直接使用VS打开项目,出现问题:XXXX已配置为使用IIS.无法访问IIS元数据库.您没有足够的特权访问计算机上的IIS网站.解决:1.以“管理员权限”运行VS,在VS菜单打开 ...

  8. Android -------- 从一个Fragment跳转到另一个Fragment

    一.直接getActivity,使用activity的fragmenttransation的replace方法替换 private void changeToAnotherFragment(){ // ...

  9. 【Linux常用命令(更新)】

    1.ifconfig:查看当前ip,网卡信息 2.df -h:查看文件系统的使用情况,挂载点信息 3.du -sh  /var:查看/var文件夹大小 4.netstat -a:查看网络联机状态 5. ...

  10. progit-zh(Git中文文档)

    发现好像在墙外,还是下载下来看会快点 链接: http://pan.baidu.com/s/1o8EiDMq 密码: vzf9