<?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. http常见错误

    100:继续  客户端应当继续发送请求.客户端应当继续发送请求的剩余部分,或者如果请求已经完成,忽略这个响应. 101: 转换协议  在发送完这个响应最后的空行后,服务器将会切换到在Upgrade 消 ...

  2. mysql中文名字按首字母排序

    在mysql数据库中可以使用GBK编码对中文进行排序,如名字按首字母排序 order by convert(substr(tu.username,1,1) using 'GBK') 其中substr方 ...

  3. UITableView的刷新

    UITableView的刷新1> 数据刷新的总体步骤* 修改模型数据* 刷新表格(刷新界面) 2> 刷新表格(刷新界面)的方法* 全局刷新(每一行都会重新刷新)- (void)reload ...

  4. CopyOnWriteArrayList理解与理解

     CopyOnWriteArrayList,因何而存在? ArrayList的一个线程安全的变体,其所有可变操作(add.set 等)都是通过对底层数组进行一次新的复制来实现的,代价昂贵. CopyO ...

  5. 最长回文字符串(manacher算法)

    偶然看见了人家的博客发现这么一个问题,研究了一下午, 才发现其中的奥妙.Stupid. 题目描述:      回文串就是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串. ...

  6. Android 中文 API (40) —— RatingBar

    Android 中文 API (40) —— RatingBar 前言 本章内容是 android.widget.RatingBar,译为"评分条",版本为Android 2.2 ...

  7. C++11 : 外部模板(Extern Template)

    在C++98/03语言标准中,对于源代码中出现的每一处模板实例化,编译器都需要去做实例化的工作:而在链接时,链接器还需要移除重复的实例化代码.显然,让编译器每次都去进行重复的实例化工作显然是不必要的, ...

  8. web性能优化——JSP

    一.啰嗦 做web开发的都知道,性能的重要性就不必强调了.就前端展示的工作来说,jsp大家都熟悉html更熟悉:web服务器tomcat应该是最熟悉的了:web方面的基础知识上来说,静态页面比动态页面 ...

  9. Hide the common top menu in Ubuntu 12.04

    隐藏:1.sudo apt-get autoremove appmenu-gtk appmenu-gtk3 appmenu-qt2.reboot 恢复: 1.sudo apt-get install ...

  10. css实现垂直居中6种方法

    在一次次笔试,一次次的面试中,问到垂直居中的问题太多太多,但是我每一次回答,都好像都不能让面试官太满意,今天特意花点时间,整理一下css垂直居中问题. 1.如果是单行文本.看代码: <!DOCT ...