标签: javafx

JavaFX:如何实现自定义工具提示

我正在尝试创建自己的 Tooltip 类。基本上,工具提示将是一个 标签,底部有一个指针图形(FontAwesomeView),全部包裹在vbox 中

我遇到的部分是,如何在屏幕上显示我的自定义工具提示而不将其添加到父节点?

java javafx javafx-2 javafx-8

0
推荐指数
1
解决办法
2807
查看次数

javafx 选择框触发方法 onchange

好的,所以我对我的 java 非常生疏,甚至在 javafx 上更是如此。so i got a choicebox "categoryDrop" that when the value of the choicebox change i want to trigger this event that then takes the value of the choicebox and compare to an object "Folder" categorylist wich is an attribute it has.

这是我的代码

  @FXML 
private void folderByCategory(ActionEvent event) {
    System.out.println("här1");
      TreeItem<DocumentObject<?>> treeRoot = new TreeItem<>(new Folder());

    for (Folder folder : logic.getFolderList()) {

        if(f.getCategoryList().contains(categoryDrop.valueProperty())){
            System.out.println("här2");
          TreeItem<DocumentObject<?>> newFolders = new TreeItem<>(folder);

          for(FileReference file : folder.getFileList()){
            System.out.println(file.getName());
            TreeItem<DocumentObject<?>> fileNode = …
Run Code Online (Sandbox Code Playgroud)

java javafx scenebuilder

0
推荐指数
1
解决办法
3072
查看次数

导出到 jar 文件时,JavaFX 应用程序不加载 fxml 文件

我刚刚完成了我的第一个 Java 项目,但是我似乎无法正确构建它。它将加载整个计算器运行的初始 fxml 文件,但是当我尝试在假期/休息菜单中添加假期/休息时,应该显示一个对话框,以便用户可以填写信息,但我一直没有得到一个位置在cmd中运行jar文件时设置错误。当我在 intellij 中启动它但不在 jar 中时,这一切都有效。

这就是我设置文件的方式。我在 FinishedCalCulator 项目中创建了一个资源目录,并将其标记为资源根

文件结构

这就是我将 FXML 文件的位置设置到加载器中的方式。当我在 Intellij 中运行它但不在 jar 文件中时,这有效。

方法调用

项目结构 项目结构

通过 CMD 运行 通过 CMD 运行

调用目标异常/位置未设置错误 调用目标异常/位置未设置错误

我环顾四周,发现一些帖子谈论将所有 fxml 文件放入资源文件中,我这样做并使其在 Intellij 中再次工作,但是当我尝试添加它们时,它仍然不会显示对话框窗格。我不确定我在这里做错了什么。我不认为我完全理解我做错了什么。任何帮助都会很棒。

javafx jar fxml

0
推荐指数
1
解决办法
1339
查看次数

ActionEvent 库(JDK 8)无法识别 IntelliJ setOnAction

我似乎对 IntelliJ 有关于setOnActionlambda 函数的问题。经过大量研究,我找不到我的问题的答案。

我正在学习用 Java(最新的 JDK 8 版本)编程,最近从 NetBeans 转移到 IntelliJ IDE。我编写了一个非常简单的程序,代码在 NetBeans 中完美运行,但是我在使用 IntelliJ 时遇到了问题。

setOnActionIntelliJ 无法识别该函数。我已经配置了 IDE(项目结构/模块/并选择了 8 - Lambda's,类型注释,...)但没有成功。我手动添加:import javafx.event.ActionEvent;

我还配置了(设置/常规/自动导入/动态添加明确的导入)。

该程序包含两个类,一个 Main 类和一个 GUI 类。

主要类:

package fxvb0203;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class fxvb0203 extends Application
{

    public static void main(String[] args)
    {
       launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
       FlowPane root = new FlowPane();
       Scene scene = new Scene(root);

       new GUI(root);

       primaryStage.setTitle("Test");
       primaryStage.setScene(scene);
       primaryStage.show(); …
Run Code Online (Sandbox Code Playgroud)

java javafx intellij-idea java-8

0
推荐指数
1
解决办法
1481
查看次数

javafx 中的 initialize() 是什么意思?

我在我的项目中写了一些代码,我发现我应该把我的buttonlistener放在public void initialize(),否则我不能使用button。我不知道 javafx 中的 initialize() 是什么意思,为什么我不能把它改成另一个方法名?

这是我代码中的 initialize 方法,我没有实现 Initializable。那么这在javafx 中是什么意思呢?

public void initialize() {
    weight_number1.setOnAction(e -> number(1));
    weight_number2.setOnAction(e -> number(2));
    weight_number3.setOnAction(e -> number(3));
    weight_number4.setOnAction(e -> number(4));
    weight_number5.setOnAction(e -> number(5));
    weight_number6.setOnAction(e -> number(6));
    weight_number7.setOnAction(e -> number(7));
    weight_number8.setOnAction(e -> number(8));
    weight_number9.setOnAction(e -> number(9));
    weight_number0.setOnAction(e -> number(0));
    weight_numberCE.setOnAction(e -> symbol(1));
    weight_numberLeft.setOnAction(e -> symbol(2));
    weight_numberp.setOnAction(e -> symbol(3));

    weight_box1.setOnAction((event) -> {
        change();
        showans();
    });
    weight_box2.setOnAction((event) -> {
        change();
        showans();
    });
}
Run Code Online (Sandbox Code Playgroud)

javafx initialization

0
推荐指数
1
解决办法
4688
查看次数

JavaFx 变化场景

我是 javaFX 的新手,对 java 有初级水平的理解。我正在尝试构建一个最终会生成表单的简单应用程序。我想在选择按钮时更改场景,但我不知道该怎么做,我读过的所有内容都超出了我的水平。`

@Override
public void start(Stage primaryStage) {

         primaryStage.setTitle("Welcome to the Log Book Generator");
         /*Defining Options on Home screen*/

         Button btnR = new Button("Repair");
         Button btnM = new Button("Maintenance");
         Button btnW = new Button("Weather");
         Button btnO = new Button ("Other");
         Button btnU = new Button ("Filter Pickup");
         Button btnVC = new Button ("Verification/Calibration");
         Button btnE = new Button ("Exit");



    /*Actions upon button selection*/    
    btnR.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            System.out.println("Repair");
        }
    });
    btnM.setOnAction(new EventHandler<ActionEvent>() …
Run Code Online (Sandbox Code Playgroud)

user-interface javafx netbeans-8

0
推荐指数
1
解决办法
3567
查看次数

如果在 ListView JavaFx 中选择了项目

如果我有一个列表和一个按钮。我希望在选择该列表中的项目之前禁用该按钮,最好的方法是什么?

java javafx

0
推荐指数
1
解决办法
1641
查看次数

JavaFx Tableview 复选框需要焦点

我在我的 tableView 中实现了布尔表示作为复选框。它通常工作正常,但非常令人恼火的事实是它需要关注行(编辑)以应用复选框值的更改。这意味着我首先必须双击该字段,然后单击复选框。

如何使复选框更改立即执行 onEditCommit?

public class BooleanCell<T> extends TableCell<T, Boolean> {
private CheckBox checkBox;

public BooleanCell() {
    checkBox = new CheckBox();
    checkBox.selectedProperty().addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (isEditing())
                commitEdit(newValue == null ? false : newValue);
        }
    });
    setAlignment(Pos.CENTER);
    this.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    this.setEditable(true);
}

@Override
public void updateItem(Boolean item, boolean empty) {
    super.updateItem(item, empty);
    if (empty) {
        setGraphic(null);
    } else {
        checkBox.setSelected(item);
        setGraphic(checkBox);
    }
}
Run Code Online (Sandbox Code Playgroud)

}

checkbox javafx tableview

0
推荐指数
1
解决办法
345
查看次数

为什么 Thread.sleep() 在 JavaFX 中不起作用?

当我使用 JavaFX 时,睡眠功能不会相应地工作。就像在这段代码中:

public class Controller {

@FXML private Label label;
@FXML private Button b1;

public void write() throws InterruptedException
{
    label.setText("FIRST TIME");
    for(int i=1;i<=5;i++)
    {
        System.out.println("Value "+i);
        label.setText("Value "+i);
        Thread.sleep(2000);
    }
    label.setText("LAST TIME");
}
Run Code Online (Sandbox Code Playgroud)

当按下按钮 b1 时,将调用写入函数。现在,在 2 秒后在控制台中打印“Value + i”。但是那个时候标签 l1 的文本没有改变,最后它只变成了“LAST TIME”。这里有什么问题?

java sleep javafx thread-sleep

0
推荐指数
1
解决办法
1846
查看次数

单击 CheckMenuItem (JavaFX) 时如何防止 MenuButton 关闭

我是 Java 新手,我想知道如何在单击项目时防止 MenuButton 弹出窗口关闭,我尝试了以下功能,我在本网站上找到了该功能,但似乎没有任何作用。我需要这个来克隆我的 C# 应用程序,以便学习 Java。

@FXML
private MenuButton menuButton;

@FXML
    void initialize() {
        CheckMenuItem menuButtonItem1 = new CheckMenuItem("Item 1");
        CheckMenuItem menuButtonItem2 = new CheckMenuItem("Item 2");
        CheckMenuItem menuButtonItem3 = new CheckMenuItem("Item 3");
        menuButtonItem1.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
           e.consume();
    }
});
        menuButtonItem2.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
           e.consume();
    }
});
        menuButtonItem3.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
           e.consume();
    }
});
}
Run Code Online (Sandbox Code Playgroud)

javafx popupmenubutton auto-close fxml

0
推荐指数
1
解决办法
741
查看次数