我有一个代码,当按下某个键时执行某些功能:
scene.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.F1) {
doSomething();
}
});
Run Code Online (Sandbox Code Playgroud)
它可以工作,但只有在没有聚焦组件的情况下,例如Button或TextField.我注意到如果我按下CTRL + F1,或ALT + F1或SHIFT + F1,它会起作用,但只有F1才有效,如果没有聚焦组件.有办法避免这种情况吗?
-----更新----- 正如@James_D所说,我可以使用eventFilter代替eventHandler:
scene.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode().equals(KeyCode.ESCAPE)) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(TelaPrincipalController.class.getResource("/br/com/atualy/checkout/layout/telaoperacoescaixa.fxml"));
Parent parent = fxmlLoader.load();
Scene scene = new Scene(parent, 600,400);
Stage stage = new Stage();
stage.setScene(scene);
stage.initModality(Modality.APPLICATION_MODAL);
stage.initOwner(this.stage);
stage.showAndWait();
System.out.println("----> THIS IS BEING PRINTED TWICE ! <----");
} catch (IOException e) {
e.printStackTrace();
}
}
});
Run Code Online (Sandbox Code Playgroud)
每次按ESC键时,此代码中的第12行打印两次.这意味着当我按下esc时,它会打开新窗口,当我关闭它时,窗口会再次打开.我可以解决吗?
我已经设置了一个具有以下依赖项的简单maven项目:
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.1-b04</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.1</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
而这个页面:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:body onkeydown="alert('You pressed some key!')">
<h:outputLabel value="Hello, young fellows!"/>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是生成的html,注意body标签没有方法:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html …
Run Code Online (Sandbox Code Playgroud) 使用此执行程序
executor = Executors.newFixedThreadPool(1);
Run Code Online (Sandbox Code Playgroud)
将一次只运行一个任务,但将按顺序执行任何后续任务.如果新任务已经运行,我希望它拒绝新任务.我应该使用其他类型的遗嘱执行人吗?哪一个?或者我应该在这里寻找不同的方法?
有没有办法在JavaFX舞台的整个场景中绘制从黑色到透明的径向渐变?我希望实现这样的目标:
我有以下命令:
git log --pretty=tformat:'<li>%h %ci %d %s</li>' > changelog.html
Run Code Online (Sandbox Code Playgroud)
这将git日志保存到changelog.html文件中.当我通过git bash执行它时,它运行正常,但是当我将此代码放在.bat文件中并运行它时,我收到以下错误:
The system could not find the specified file
我认为这是由格式参数的引号引起的,但我不知道如何解决问题...有没有办法逃避引号呢?
我试图在JavaFX(使用JavaFX 8)上为Label的文本填充设置动画.我的目标是使渐变的第一种颜色每半秒从黄色变为红色.我试过这个:
Timeline timeline = new Timeline();
timeline.setCycleCount(Animation.INDEFINITE);
timeline.setAutoReverse(true);
LinearGradient fill1 = new LinearGradient(50,50,200,200,false, CycleMethod.NO_CYCLE, new Stop(0.1f, Color.YELLOW), new Stop(1.0f, Color.BLACK));
LinearGradient fill2 = new LinearGradient(50,50,200,200,false, CycleMethod.NO_CYCLE, new Stop(0.1f, Color.RED), new Stop(1.0f, Color.BLACK));
KeyValue keyValue1 = new KeyValue(labelInstrucoes.textFillProperty(), fill1, Interpolator.EASE_OUT);
KeyValue keyValue2 = new KeyValue(labelInstrucoes.textFillProperty(), fill2, Interpolator.EASE_OUT);
KeyFrame keyframe1 = new KeyFrame(Duration.millis(0), keyValue1);
KeyFrame keyframe2 = new KeyFrame(Duration.millis(500), keyValue2);
timeline.getKeyFrames().addAll(keyframe1, keyframe2);
timeline.play();
Run Code Online (Sandbox Code Playgroud)
但它没有用.但是,如果不使用LinearGradient,我会使用简单的颜色,如下所示:
KeyValue keyValue1 = new KeyValue(labelInstrucoes.textFillProperty(), Color.YELLOW, Interpolator.EASE_OUT);
KeyValue keyValue2 = new KeyValue(labelInstrucoes.textFillProperty(), Color.RED, Interpolator.EASE_OUT);
Run Code Online (Sandbox Code Playgroud)
有用.那么,如何为渐变设置动画?
我的语言是葡萄牙语,所以我需要写一个doSomething()
用葡萄牙语写的方法façaAlgo()
.Java允许我在代码中使用特殊字符,但它是否安全?这样做的缺点是什么?或者我可以使用它而不用担心?
在我web.xml
,我有这个配置条目:
<context-param>
<param-name>javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR</param-name>
<param-value>true</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
但是,我不希望它永远存在true
.我想根据情况设置它true
或false
在我的托管bean中.那可能吗?
我ImageView
想在其中一张一张地显示两张图像。我希望这两个图像之间的过渡具有淡入淡出效果。这是我尝试过的:
KeyFrame keyFrame1On = new KeyFrame(Duration.seconds(.2), new KeyValue(imageView.imageProperty(), image1, Interpolator.EASE_OUT));
KeyFrame keyFrame2On = new KeyFrame(Duration.seconds(.5), new KeyValue(imageView.imageProperty(), image2, Interpolator.EASE_OUT));
Timeline timelineOn = new Timeline(keyFrame1On, keyFrame2On);
timelineOn.setAutoReverse(false);
timelineOn.play();
Run Code Online (Sandbox Code Playgroud)
但图像之间的过渡是坚实的,没有褪色。我究竟做错了什么?
我有一个带有复选框的第一列的 TableView。
我设法正确显示复选框并使其可编辑,但是当我单击复选框以选中或取消选中时,复选框会更改但它不会更新我的模型。
我是这样做的:
TableColumn<ContasReceber, Boolean> myCheckBoxColumn = (TableColumn<ContasReceber, Boolean>) tabelaContas.getColumns().get(0);
myCheckBoxColumn.setCellFactory(p -> new CheckBoxTableCell<>());
myCheckBoxColumn.setOnEditCommit(evt -> evt.getRowValue().setChecked(evt.getNewValue()));//It never executes the method setChecked when i click on the checkBox to change it's values.
Run Code Online (Sandbox Code Playgroud) 假设我有一些包含一些字符和数字的文本,就像这样:
Lorem ipsum 10.2357 dolor sit amet, 10.0000 consectetur adipiscing 50.9651 elit.
我怎么能得到这样的最终字符串:
Lorem ipsum 10.23 dolor sit amet, 10.00 consectetur adipiscing 50.96 elit.
使用单个语句,而无需创建其他方法?
- >更新 我想在一个语句中执行此操作,因为我想在jasper报告中执行此操作,而jasper报告不支持多语句.我可以为此创建一个方法,但这对于一个简单的事情来说太过分了
我有一个通过Primefaces JSF组件中的一些事件触发的ajax事件.
我希望此事件仅处理包含此事件的特定字段的值,但不更新任何内容,仅处理.像这样的东西:
<p:ajax event="itemSelect" process="@this" update="@none"/>
Run Code Online (Sandbox Code Playgroud)
这样的事可能吗?
假设我想从我的存储库中看到所有git更改.我所做的是在Windows控制台上执行以下命令:
git log --oneline --decorate
Run Code Online (Sandbox Code Playgroud)
所以我可以在控制台上看到完整的历史记录.
但是,如果我想将其保存在文件中,将其发送到客户端呢?我知道我可以捕获控制台的输出进行一些编码,但我认为必须有一种方法可以简单地将其保存在文件中.像这样的git log --oneline --decorate --SaveToFile
东西怎么样这样的事情呢?
java ×8
javafx ×5
javafx-2 ×4
javafx-8 ×4
jsf ×3
git ×2
jsf-2 ×2
primefaces ×2
ajax ×1
bash ×1
batch-file ×1
concurrency ×1
windows ×1