如何在两个javafx样式表之间切换(switch between two javafx stylesheets)

JavaFX应用程序的示例代码显示了如何使用JavaFXCSS设置图形用户界面的样式。有两个JavaFX样式表-StyleForm.css和StyleForm2.css。...

JavaFXCSS示例程序

JavaFX应用程序的示例代码显示了如何使用JavaFXCSS设置图形用户界面的样式。有两个JavaFX样式表-StyleForm.css和StyleForm2.css。

按下“更改样式”按钮时,JavaFX应用程序将在这两种样式之间切换。它还显示了如何使用内联样式在VBox布局窗格周围放置边框。

styleform.css

.根{

styleform2.css

.根{

java应用程序

导入javafx.application.application;导入javafx.event.actionevent;导入javafx.event.eventhandler;导入javafx.scene.scene;导入javafx.geometry.pos;导入javafx.scene.control.button;导入javafx.scene.control.label;导入javafx.scene.control.checkbox;导入javafx.scene.layout.hbox;导入javafx.scene.layout.vbox;导入javafx.scene.layout.borderpane;导入javafx.stage.stage;导入javafx.geometry.insets;/***@作者编写*/public-class-styleform扩展应用程序{final-string-style1=“/javafxcsscontrols/styleform.css”;final-string-style2=“/javafxcsscontrols/styleform2.css”;final-string-feedbacklabeltext=“stylesheet-loaded:”;final-string-borderstyle=“borders”;final-string-borderstyle2=“borders”@覆盖公共无效(final stage primarystage){final borderpane pane=new borderpane();final vbox controlbox=new vbox(10);hbox buttonbox=new hbox(10);hbox randomcontrolbox=new hbox(10);hbox feedbackbox=new hbox(10);final scene scene=new scene(pane,700500);//设置场景以使用第一个样式表场景。getstylesheets()。添加(样式1);//设置vbox以使用样式表控制框中的fontstyle.getstyleclass().add(“fontstyle”);最终标签feedbacklabel=新标签(feedbacklabeltext+style1);标签borderlabel=新标签(“这里有一些随机文本”);//选中或取消选中复选框时,将为//controlbox vbox布局窗格围绕是否显示边框复选框borders=new复选框(“使用边框”);borders.setonaction(new eventhandler(){@override public void handle(actionevent e){if(!controlbox.getstyle().contains(“black”){controlbox.setstyle(“-fx边框颜色:黑色;-fx边框样式:虚线;-fx边框宽度:2;”;}其他{controlbox.setstyle(“-fx边框宽度:0;”;”;}}});//单击按钮时,当前样式表将从场景中清除//它将被另一个样式表替换以更改应用程序的外观//标签跟踪正在使用的样式表按钮changestylesheet=new按钮(“更改样式”);changestylesheet.setonaction(new eventhandler(){@override public void handle(actionevent e){if(scene.getstylesheets().contains(style1)){scene.getstylesheets().clear();scene.getstylesheets().add(style2);feedbacklabel.settext(feedbacklabeltext+style2);}else{scene.getstylesheets().clear();scene.getstylesheets().add(style1);feedbacklabel.settext(feedbacklabeltext+style1);}});buttonbox.setpadding(新插图(10));buttonbox.getchildren().add(更改样式表);buttonbox.setalignment(位置居中);randomcontrolbox.getchildren().add(边界标签);randomcontrolbox.getchildren().add(边界);feedbackbox.setpadding(新插图(10,10,1,0));feedbackbox.getchildren().add(反馈标签);controlbox.getchildren().add(randomcontrolbox);pane.setpadding(新插图(10,10,1,10));pane.settop(按钮盒);pane.setcenter(控制盒);pane.setbottom(feedbackbox);primarystage.settitle(“设置javafx控件样式”);primarystage.setscene(场景);primarystage.show();}/***在正确部署的javafx应用程序中忽略main()方法。*main()仅在无法通过部署工件*启动应用程序时用作回退,例如在fx*支持有限的IDE中。netbeans忽略main()*@param args命令行参数*/public static void main(string[]args){launch(args);}
  • 发表于 2021-09-12 23:42
  • 阅读 ( 96 )
  • 分类:IT

你可能感兴趣的文章

了解如何使用react native编写自己的android应用程序

... import React from 'react';import { StyleSheet, Text, View } from 'react-native';export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Open up App.js to start...

  • 发布于 2021-03-23 19:10
  • 阅读 ( 241 )

使用css格式化文档以便打印

... <link href="base.css" rel="stylesheet" /> ...

  • 发布于 2021-03-28 16:05
  • 阅读 ( 238 )

notepad++是否支持使用数字在选项卡之间切换?

...otepad++中的选项卡之间切换: Notepad++ supports either switching between the most recently used tabs or adjacent tabs (depending on Notepad++’s configuration). I was hoping to switch between tabs using Ctrl+1, Ctrl+2, etc. just as I do with Google Chrome. This functionality does not seem...

  • 发布于 2021-04-10 21:52
  • 阅读 ( 70 )

极客狂言:为什么这么多网站没有使用打印样式表?

...日后使用,而不会浪费纸张。 什么是打印样式表(print stylesheets)? 大多数网站实现打印功能时都会将您转到另一个页面,打印机的格式会有所不同,但这并不是必须的。每个浏览器都实现一种简单的CSS技术,称为打印样式表,...

  • 发布于 2021-04-12 23:31
  • 阅读 ( 162 )

静止的(static)和动摩擦(kinetic friction)的区别

...动时,静摩擦力已达到最大值。 The maximum static friction ( ) between two surfaces is given by where is the size of the normal contact force between the two surfaces. is called the coefficient of static friction and has a c***tant value for two types of surfaces. e.g.  for steel...

  • 发布于 2021-06-27 03:53
  • 阅读 ( 184 )

过道(aisle)和小岛(isle)的区别

...ing is related to politics. In politics; aisle refers to an imaginary line between two political parties. In the United States, the phrase “the two sides of the aisle” refers to the two major political parties, the Republicans and the Democrats. Therefore, “crossing the aisle” refers to swit...

  • 发布于 2021-06-27 18:22
  • 阅读 ( 341 )

模式开关(mode switch)和过程开关(process switch)的区别

...除此PCB。模式切换和进程切换是操作系统中与进程相关的两个术语。 覆盖的关键领域 1.什么是模式切换-定义,功能2.什么是流程切换-定义,功能3.模式切换和流程切换的区别是什么-关键区别的比较 关键术语 操作系统、模式开...

  • 发布于 2021-07-01 14:48
  • 阅读 ( 299 )

如何创建网站第二部分:样式和css

...his p tag will be red, 20-pixels wide, and use Helvetica.<p>Internal stylesheets: Inside the document (often inside the head), you can define styles for elements in the page using selectors. Internal stylesheets look like this: <code><style type="text/css"> h3 { ...

  • 发布于 2021-07-24 23:08
  • 阅读 ( 293 )

@进口(@import)和css的链接?(link for css?)的区别

...样式表。Firefox、Safari和Opera等浏览器都支持rel=“alternate stylesheet”属性,如果有可用的属性,则允许查看者在它们之间切换。您还可以使用JavaScript切换器在IE中的样式表之间切换,出于可访问性的目的,最常用于缩放布局。 使...

  • 发布于 2021-09-05 00:08
  • 阅读 ( 156 )

如何阻止使用css打印网页(block a web page from printing with css)

...需在HTML页面的“head”元素中添加以下行。 <link rel="stylesheet" type="text/css" href="print.css" media="print" /> 此信息告诉浏览器,如果此网页设置为打印,则使用此样式表,而不是页面用于屏幕显示的任何默认样式表。当页面切...

  • 发布于 2021-09-05 00:22
  • 阅读 ( 211 )
有意思吗25416
有意思吗25416

0 篇文章

相关推荐