免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
标题窗格就是带有标题的面板,可以被打开和关闭,也可以被包进任何Node元素,诸如UI控件、图片、计入布局容器的元素组。标题窗格可以用手风琴控件来形成组。手风琴控件能创建多个窗格而每次只显示一个。Figure 20-1是带有3个标题窗格的手风琴控件。Figure 20-1 Accordion with Three Titled PanesDescription of Figure 20-1 Accordion with Three Titled PanesJavaFX SDK API中的Accordion和TitledPane类用来实现这样的控件。创建Titled Panes创建TitledPane控件要定义一个标题和一些内容。可以使用TitledPane类的带有两个参数的构造方法,或者单独使用setText和setContent方法也行。两种方法都在Example 20-1中 .Example 20-1 Declaring a TitledPane Object/using a two-parameter constructor TitledPane tp = new TitledPane(My Titled Pane, new Button(Button); /applying methods TitledPane tp = new TitledPane(); tp.setText(My Titled Pane); tp.setContent(new Button(Button);它们的效果系统,都是Figure 20-2.Figure 20-2 Titled Pane with a ButtonDescription of Figure 20-2 Titled Pane with a Button标题窗格可以改变大小来适应它的内容。可以添加多行文本,结果见Figure 20-3.Figure 20-3 Titled Pane with Some TextDescription of Figure 20-3 Titled Pane with Some Text不要明确指定标题窗格的最小、最大和优先的高度值,这样在打开关闭时可能导致难以预料的行为。Example 20-2在的代码添加了几个控件到标题窗格,然后加入到了GridPane布局容器。Example 20-2 Titled Pane with the GridPane Layout ContainerTitledPane gridTitlePane = new TitledPane();GridPane grid = new GridPane(); grid.setVgap(4); grid.setPadding(new Insets(5, 5, 5, 5); grid.add(new Label(First Name: ), 0, 0); grid.add(new TextField(), 1, 0); grid.add(new Label(Last Name: ), 0, 1); grid.add(new TextField(), 1, 1); grid.add(new Label(Email: ), 0, 2); grid.add(new TextField(), 1, 2);gridTitlePane.setText(Grid);gridTitlePane.setContent(grid);运行的结果是Figure 20-4。Figure 20-4 Titled Pane that Contains Several ControlsDescription of Figure 20-4 Titled Pane that Contains Several Controls可以定义标题窗格打开关闭的方式。默认地,标题窗格是可伸缩的,它们的移动也是动画。如果要阻止标题窗格关闭,将setCollapsible方法设为false。也可以将setAnimated方法设为false来关闭动画打开效果。Example 20-3中的代码实现了该任务。Example 20-3 Adjusting the Style of a Titled PaneTitledPane tp = new TitledPane(); /prohibit closing tp.setCollapsible(false); /prohibit animating tp.setAnimated(false);将Titled Panes加入到Accordion在应用中,可以单独使用标题窗格,也可以使用Accordion把控件编组。同样也不要指定手风琴控件的高度值。将几个标题窗格加入到手风琴很类似把开关按钮加入到开关组:每次只能打开手风琴中的一个标题窗格。Example 20-4创建了3个标题窗格并加入到了手风琴中。Example 20-4 Accordion and Three Titled Panesimport javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Accordion; import javafx.scene.control.TitledPane; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.stage.Stage; public class TitledPaneSample extends Application final String imageNames = new StringApples, Flowers, Leaves; final Image images = new ImageimageNames.length; final ImageView pics = new ImageViewimageNames.length; final TitledPane tps = new TitledPaneimageNames.length; public static void main(String args) launch(args); Override public void start(Stage stage) stage.setTitle(TitledPane); Scene scene = new Scene(new Group(), 80, 180); scene.setFill(Color.GHOSTWHITE);final Accordion accordion = new Accordion ();for (int i = 0; i imageNames.length; i+) imagesi = newImage(getClass().getResourceAsStream(imageNamesi + .jpg);picsi = new ImageView(imagesi);tpsi = new TitledPane(imageNamesi,picsi);accordion.getPanes().addAll(tps);accordion.setExpandedPane(tps0);Group root = (Group)scene.getRoot(); root.getChildren().add(accordion); stage.setScene(scene); stage.show(); 用循环创建了3个标题窗格,每个的内容都是ImageView对象。把标题窗格加入到手风琴中要使用getPanes和addAll方法。可以用add方法代替addAll方法来加入单个标题窗格。默认地,应用启动后所有窗格都关着。setExpandedPane方法指定了带有苹果图片的窗格要打开。见Figure 20-5.Figure 20-5 Accordion with Three Titled PanesDescription of Figure 20-5 Accordion with Three Titled Panes处理Accordion事件可以使用标题窗格和手风琴程序不同的数据。Example 20-5创建了一个单独的标题窗格放进GridPane悲剧容器和三个标题窗格放进手风琴中。单独的窗格包含了一个email客户端元素,手风琴使得选择窗格会显示相应的图片。Example 20-5 Implementing ChangeListener for an Accordionimport javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Accordion; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.TitledPane; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.paint.Color; import javafx.stage.Stage; public class TitledPaneSample extends Application final String imageNames = new StringApples, Flowers, Leaves; final Image images = new ImageimageNames.length; final ImageView pics = new ImageViewimageNames.length; final TitledPane tps = new TitledPaneimageNames.length; final Label label = new Label(N/A); public static void main(String args) launch(args); Override public void start(Stage stage) stage.setTitle(TitledPane); Scene scene = new Scene(new Group(), 800, 250); scene.setFill(Color.GHOSTWHITE); / - GridPane container TitledPane gridTitlePane = new TitledPane(); GridPane grid = new GridPane(); grid.setVgap(4); grid.setPadding(new Insets(5, 5, 5, 5); grid.add(new Label(To: ), 0, 0); grid.add(new TextField(), 1, 0); grid.add(new Label(Cc: ), 0, 1); grid.add(new TextField(), 1, 1); grid.add(new Label(Subject: ), 0, 2); grid.add(new TextField(), 1, 2); grid.add(new Label(Attachment: ), 0, 3); grid.add(label,1, 3); gridTitlePane.setText(Grid); gridTitlePane.setContent(grid); / - Accordion final Accordion accordion = new Accordion (); for (int i = 0; i imageNames.length; i+) imagesi = new Image(getClass().getResourceAsStream(imageNamesi + .jpg); picsi = new ImageView(imagesi); tpsi = new TitledPane(imageNamesi,picsi); accordion.getPanes().addAll(tps);accordion.expandedPaneProperty().addListener(newChangeListener() public void changed(ObservableValue ov,TitledPane old_val, TitledPane new_val) if (new_val != null) label.setText(accordion.getExpandedPane().getText() +.jpg););HBox hbox = new HBox(10); hbox.setPadding(new Insets(20, 0, 0, 20); hbox.getChildren().setA
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 大米成品库及低温房式仓建设项目可行性研究报告模板-申批备案
- 2026年婚姻家庭咨询师一级(高级技师)专业能力冲刺模拟考试卷及答案(十八)
- 2026年环境影响评价工程师资格考试环境影响评价技术导则与标准冲刺模拟考试卷及答案(十六)
- 事业单位综合岗面试历年真题试卷及答案
- 2026年项目合作伙伴变更告知函(7篇)范文
- 律师顾问案件处理效能考核表
- 2026年年度业务合作总结通知(4篇)
- 关于技术转化合作意向的商务邀请函(3篇)
- 机械制造进度管理绩效考核表
- 2026年婚姻家庭咨询师二级(技师)理论知识冲刺模拟考试卷及答案(共二十套)
- 2026乌当区社区工作者(五岗)选聘60人笔试参考题库及答案解析
- 2026重庆綦江区国有企业社会招聘管理人员15人笔试参考题库及答案解析
- 2026年中级经济师《建筑与房地产经济》真题及答案
- 国家宪法主题课件
- 新版2026年新教材统编版九年级上册道德与法治期末复习全册考点提纲
- 《跨越边界的社区:北京》阅读记录
- 《JBT 20114.4-2009 糖浆剂瓶封口机》专题研究报告
- 《JBT 10789-2007高压晶体炉 TDR-GY系列液封直拉法高压晶体炉》专题研究报告
- 2026年希望杯IHC五年级数学竞赛试卷(W卷)(含详解)
- 护理敏感指标与患者安全
- (2025年)福建能化集团招聘笔试题附答案
评论
0/150
提交评论