import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.OverrunStyle;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class BindTooltipToFocusEvent extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("How to bind tooltip to focus event?");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(5);
grid.setPadding(new Insets(25, 25, 25, 25));
grid.add(new Label("Email"), 0, 0);
grid.add(new TextField(), 0, 1);
grid.add(new Label("Password"), 0, 2);
Tooltip tooltip = new Tooltip("Paswords must contain 1-50 characters, etc...");
tooltip.setWrapText(true);
tooltip.setTextOverrun(OverrunStyle.ELLIPSIS); …Run Code Online (Sandbox Code Playgroud) 如何判断javafx.scene.media.MediaPlayer是否正在播放?最好不要对构建路径进行任何外部导入或添加.如果这是不可能的,那么我可以使用任何自包含的库吗?我正在ARM CPU上安装此软件,所以我试图使这段代码尽可能简约.我只会使用这个框架播放音乐文件,主要是MP3.有关如何判断玩家是否正在使用此库或其他库播放音乐的任何建议?
我已经创建了一个Java/JavaFX控制台,现在我面临一个例外:Console reports an Internal error.The error is: java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-5.控制台的代码:
package core.console;
import javafx.concurrent.Service;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
import java.io.*;
import java.util.ResourceBundle;
public class Console implements Runnable{
private Console(ResourceBundle resourceBundle) throws IOException {
FXMLLoader loader = new FXMLLoader(this.getClass().getResource("Console.fxml"), resourceBundle);
Parent root = (Parent) loader.load();
controller = loader.getController();
Scene scene = new Scene(root);
stage = new Stage();
stage.setScene(scene);
textArea = controller.getTextArea();
show();
PipedOutputStream pout=new PipedOutputStream(this.pin);
System.setOut(new PrintStream(pout,true)); …Run Code Online (Sandbox Code Playgroud) 所以我当然直接创建一个简单的例子.
public class Main extends Application {
URL bla = getClass().getResource("/sample.fxml");
@Override
public void start(Stage primaryStage) throws Exception{
//If you get weird errors: http://zenjava.com/javafx/maven/fix-classpath.html
//but not actually my issue. Example displays fine in intellij.
try {
FXMLLoader loader = new FXMLLoader(bla);
Parent root = loader.load(bla);
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root));
primaryStage.show();
Controller controller = loader.<Controller>getController() ;
assert(controller != null);
controller.getLabel().setText("Kaboom!");
} catch (Exception e) {
// Exception gets thrown if the fxml file could not be loaded
e.printStackTrace();
}
}
public …Run Code Online (Sandbox Code Playgroud) 如在Google搜索框中输入,点击ENTER即可激活搜索
几天前我刚刚介绍了JavaFX和Scene Builder,所以我在这里学习基础知识.我有最新版本的JavaFX,并使用Scene Builder来促进动作事件.此外,任何指向相关教程的指针都会有所帮助.在当天的某个时刻,我专注于Scene Builder编码面板的键盘部分,特别是"On Key Released"事件没有结果.提前致谢
这是我想要做的一个粗略的想法:
@FXML
Text Field theTextField;
@FXML
Button theButton;
@FXML
void ButtonPressed() {
//do stuff here
}
@FXML
//when ENTER is pressed the button is activated
void textFieldEnterPressed() {
ButtonPressed();
}
Run Code Online (Sandbox Code Playgroud) 我需要绑定主控制器中不同fxml的控件.我有3个名为MainView.fxml,ChildView1.fxml和ChildView2.fxml的fxml文件.
MainView.fxml
<AnchorPane fx:id="view" prefHeight="280.0" prefWidth="500.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="binding.example2.MainViewController">
<children>
<VBox prefHeight="280.0" prefWidth="500.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<fx:include fx:id="child1" source="ChildView1.fxml" />
<fx:include fx:id="child2" source="ChildView2.fxml" />
</children>
</VBox>
</children>
</AnchorPane>
Run Code Online (Sandbox Code Playgroud)
ChildView1.fxml
<AnchorPane fx:id="view" prefHeight="78.0" prefWidth="464.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="binding.example2.ChildView1Controller">
<children>
<HBox layoutX="32.0" layoutY="14.0" prefHeight="51.0" prefWidth="200.0" spacing="10.0">
<children>
<Button fx:id="button1" mnemonicParsing="false" prefHeight="37.0" text="Button1" />
<Button fx:id="button2" mnemonicParsing="false" prefHeight="37.0" text="Button2" />
</children>
</HBox>
</children>
</AnchorPane>
Run Code Online (Sandbox Code Playgroud)
ChildView2.fxml
<AnchorPane fx:id="view" prefHeight="244.0" prefWidth="568.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="binding.example2.ChildView2Controller">
<children>
<TableView fx:id="tableView" prefHeight="244.0" prefWidth="568.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> …Run Code Online (Sandbox Code Playgroud) 我有一个班级,如:
public class myClass{
int age;
String name;
public String toString(){
return name;
};
}
public static ObservableList<myClass> myClassList;
Run Code Online (Sandbox Code Playgroud)
我想知道是否有可能
ChoiceBox<myClass> choiceChart = new ChoiceBox<>(myClassList);
Run Code Online (Sandbox Code Playgroud)
谢谢
PS我想有类似的情况
但使用ChoiceBox
编辑:
这是我的情况:我有一个tableView,在其中一个列中我必须使用toString()方法从myClass类型的对象设置一个String.
我试过用这些方法(其中myClass - > CustomInternalWindow类)
public static class Indicators{
private final SimpleStringProperty tool_col;
private final SimpleStringProperty chart_col;
private final SimpleStringProperty pane_col;
private final SimpleBooleanProperty on_col;
private Indicators(String tl, CustomInternalWindow chrt, String pne, Boolean sel){
this.tool_col = new SimpleStringProperty (tl);
if (chrt == null) {
this.chart_col = null;
}
else …Run Code Online (Sandbox Code Playgroud) 我在申请中面临一个奇怪的问题.
我想在两个不同的选项卡上复制UI(即两个不同的选项卡将在其容器中保存相同的VBox对象).
我期待的是,而不是创建两个不同的VBox对象添加到Tab1和Tab2我将创建一个单独的VBox对象,填充所需的内容,然后将相同的对象添加到Tab1和Tab2.
目前正在发生的事情是如果我将该UI添加到Tab1然后它才能正确显示.但是如果我向Tab2添加相同的对象,那么它将从Tab1中消失.
下面是我正在使用的示例代码.
@FXML
private Tab tab1, tab2;
Label label=new Label("Sample");
tab1.setContent(label);
tab2.setContent(label);
Run Code Online (Sandbox Code Playgroud)
我在这两个标签内容中的假设是什么,我将看到示例文本.
但是示例文本仅显示在Tab2而不是Tab1中.(Tab1显示为空.)
我是Javafx的新手,所以如果我问一个愚蠢的问题,请耐心等待:)
嗨,IllegalArgumentException当我点击任何控件或场景的空白区域时,我得到了.下面是堆栈跟踪.我不能为每个控件编写一个方法MouseEvent.当我点击场景中的空白区域或禁用的控件时,你能否建议一个解决方案来取消这个鼠标事件.
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1435)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3324)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3164)
at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3119)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1559)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2261)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:228)
at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
at com.sun.glass.ui.View.notifyMouse(View.java:922)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:722)
Run Code Online (Sandbox Code Playgroud) 尽管在设置文本之前设置了id,但事件处理程序之前的代码中的Text对象并没有改变颜色。但是,文本将随着文本设置的填充而改变颜色。我很好奇的一件事是,在CSS中,颜色不会随着.text{}OR 改变#Sign-In-Text{}。我只是不正确地使用CSS吗?
Java代码:
public class CSSTrial1 extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("CSS Trial");
stage.setResizable(false);
final GridPane grid = new GridPane();
ColumnConstraints constraints = new ColumnConstraints();
grid.getColumnConstraints().add(constraints);
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25));
grid.add(new Label("Character Name:"), 0, 0);
final TextField nameField = new TextField("");
nameField.setPromptText("Randel James");
grid.add(nameField, 1, 0);
grid.add(new Label("Weapon:"), 0, 1);
final ComboBox<String> weapons = new ComboBox<>();
weapons.getItems().addAll("Katsuragi x2", "Assault Rifle",
"Pistol", "RPG-7", "Barret 50. Cal");
grid.add(weapons, 1, 1);
HBox …Run Code Online (Sandbox Code Playgroud) javafx-2 ×10
java ×5
arm ×1
audio-player ×1
css ×1
fxml ×1
javafx ×1
javafx-8 ×1
jconsole ×1
mouseevent ×1
mp3 ×1
scenebuilder ×1
tabs ×1