标签: javafx

在标题窗格中添加内容

我想在 TitlePana 中添加几个 TreeView。

private static TitledPane pane = new TitledPane("Connections", null);


public static void initTree(String name)
    {
        pane.setContent(tree(name));
    }

pane.setContent(<node>);
Run Code Online (Sandbox Code Playgroud)

但是当我添加 TreeView 时,新节点总是替换旧节点。这是设计问题吗。知道这是一个代码问题吗?

javafx javafx-2 javafx-8

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

在淡入和淡出过渡之间更改标签文本

我正在尝试在淡入和淡出之间更改标签的文本,如下所示:

    Label label = (Label) this.cardsValueGroup.getChildren().get(1);
    label.textProperty().set(String.valueOf(cardsValue));

    SequentialTransition t = new SequentialTransition();

    if (this.cardsValueGroup.getOpacity() == 1.0) {
        FadeTransition fadeOut = new FadeTransition(Duration.seconds(0.5), this.cardsValueGroup);
        fadeOut.setFromValue(1.0);
        fadeOut.setToValue(0.0);
        t.getChildren().add(fadeOut);
    }

    FadeTransition fadeIn = new FadeTransition(Duration.seconds(0.5), this.cardsValueGroup);
    fadeIn.setFromValue(0.0);
    fadeIn.setToValue(1.0);

    t.getChildren().add(fadeIn);
    t.play();
Run Code Online (Sandbox Code Playgroud)

如何添加标签文本过渡?

label javafx transitions

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

如何在 JavaFX 的树视图中获取所有选定的树项

我需要能够在树视图(其中有多个选择)中获取所有选定项目的更新列表。

此示例:javafx2 中的树项选择事件

显示如何一次响应/识别一个选定的项目。有没有办法一次获得所有选定的项目?类似于下面假设的非工作代码:

ArrayList<TreeItem> selectedTreeItems = new ArrayList<>();

myTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            selectedTreeItems.clear();//reset the list. correct?

            //get a new list of children of the root
            ObservableList objects = myTreeView.getRoot().getChildren();

            //loop to get the selected items.
            for (int i = 0; i < objects.size(); i++) {
                TreeItem object = (TreeItem) objects.get(i);
                if (thisObjectIsSelected(object)) {
                    selectedTreeItems.add(object);
                }
            }


        }
    });

    privatevoid thisObjectIsSelected(TreeItem item){
    //what do I do here?
    }
Run Code Online (Sandbox Code Playgroud)

我不确定如何实现我想要的。任何帮助是极大的赞赏!

treeview javafx getselection java-8

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

如何删除 JavaFX 应用程序中的标准窗口菜单?

我需要没有边框和顶部菜单的简单框架,这可能吗?

java javafx menu sandbox

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

在 javafx 中更改按钮 textFill 属性

使用 javafx,我有一个按钮,在 css 属性中将 textFill 设置为白色。然后在运行时需要更改它,这在以下代码中发生:

import javafx.scene.control.Button;
import javafx.scene.paint.Color;

public class QAButton extends Button {

    public QAButton(String text) {
        this.textProperty().set(text);
    }

    public void setAnswerVisible(Boolean vis) {

        if (vis) this.setTextFill(Color.GREEN);
        else this.setTextFill(Color.BLUE);
    }

}
Run Code Online (Sandbox Code Playgroud)

但是它不会做任何事情,textFill 将保持白色。在运行时我可以做些什么来改变它?谢谢你。

编辑:我应该添加 css 代码:

.button {
    -fx-text-fill: white;
}
Run Code Online (Sandbox Code Playgroud)

并且按钮的 id 设置为

#question {
    -fx-background-color: darkblue;
    -fx-background-radius: 0;
    -fx-max-width: 2000px;
    -fx-max-height: 200px;
    -fx-min-height: 80px;
}
Run Code Online (Sandbox Code Playgroud)

javafx button

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

ContextMenu 和以编程方式选择一个项目

似乎没有用于以编程方式“选择”ContextMenu 项目的 API?选择我的意思是相当于点击上下键(或将鼠标悬停在项目上)。当显示 ContextMenu 时,我真的只需要选择第一项。我试图在显示菜单时触发向下键事件,但没有发生任何事情......也许我错误地构建了该事件。

javafx

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

在 JavaFX 树视图中,如何为所有项目设置图标?

我有一个包含文件夹和子文件夹的树视图。子文件夹的叶子是 json 文件。我已经为文件夹和叶子设置了图标。现在,只有根文件夹有图像。展开时,子文件夹会以箭头标记列出,但不会列出文件夹图标。展开箭头时,会显示图标。如何解决这个问题?

  private  Node rootIcon = new ImageView(new Image(Main.class.getResourceAsStream("images/folder2.png")));
  private  Node jsonImage = new ImageView(new Image(Main.class.getResourceAsStream("images/jsonImage1.png")));

public ObservableList<TreeItem<File>> buildChildren(TreeItem<File> treeItem) {
    File f = treeItem.getValue();
    f.getName();
    if(treeItem.getValue().isDirectory()){
    treeItem.setGraphic(rootIcon);
    }else{
        treeItem.setGraphic(jsonImage);
    }
        if (f != null) {
        File[] files = f.listFiles();
        if (files != null) {
            ObservableList<TreeItem<File>> children = FXCollections.observableArrayList();
            ChildTreeItem child2=null;
            ChildFileTreeItem childFiles=null;
            for (File childFile : files) {
                try {
                    if(childFile.isDirectory()){
                    child2 = new ChildTreeItem(childFile);
                    //child2.setSplitPane(ApplicationContext.getSplitPane());
                    children.add(child2);
                    }else{
                        childFiles=new ChildFileTreeItem(childFile);
                        //childFiles.setSplitPane(ApplicationContext.getSplitPane());
                        childFiles.setGraphic(jsonImage);
                        children.add(childFiles);
                    }
                } catch (Exception e) …
Run Code Online (Sandbox Code Playgroud)

javafx

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

为什么我不能从事件监听器调用方法,但可以在课堂的其他地方?

我在控制器类中有以下代码,用于为组合框提供事件侦听器的 JavaFX GUI:

courseComboBox.getSelectionModel().selectedItemProperty()
                .addListener(new ChangeListener<String>() {
                    @Override
                    public void changed(
                            ObservableValue<? extends String> selected,
                            String oldValue, String newValue) {

                           // Do stuff

    }
});
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试从其中调用另一个方法时,我无法:

courseComboBox.getSelectionModel().selectedItemProperty()
                    .addListener(new ChangeListener<String>() {
                        @Override
                        public void changed(
                                ObservableValue<? extends String> selected,
                                String oldValue, String newValue) {

                                this.setClassList(courseProcessed);

                               // Do Stuff

   }
});
Run Code Online (Sandbox Code Playgroud)

不过,我可以在班级的其他地方调用该方法。更具体地说,我可以initialize()在该侦听器所在的控制器中的函数中调用它。为什么我会遇到这个问题?

java oop javafx event-listener

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

加载FXML文件时为什么会收到javafx.fxml.LoadException?

我正在使用Java JDK 13和FontAwesomeFX 11。

我有一个FXML文件,其中包含一些FontAwesomeIconViews,但是将文件加载到控制器中时,我得到的是javafx.fxml.LoadException。这是FXML文件的样子:

<?xml version="1.0" encoding="UTF-8"?>

<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox id="window" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <BorderPane id="upper" fx:id="upper" prefHeight="50.0" prefWidth="800.0" stylesheets="@style.css">
         <left>
            <Label text="TEXT" BorderPane.alignment="CENTER">
               <font>
                  <Font size="20.0" />
               </font>
            </Label>
         </left>
         <right>
            <HBox prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
               <children>
LINE 27           <FontAwesomeIconView glyphName="WINDOW_MINIMIZE" size="20" />
                  <FontAwesomeIconView glyphName="CLOSE" size="30" />
               </children></HBox>
         </right>
      </BorderPane>
      <AnchorPane id="body" prefHeight="554.0" prefWidth="800.0">
         <children> …
Run Code Online (Sandbox Code Playgroud)

java javafx fxml

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

Java中的圆形窗格

我一直在进行一个项目,该项目需要使用JavaFX的Pane圈显示节点。

这是一所大学的工作,因此我不能将外部库用作JFxtras。

做一些研究后,我在stackoverflow中发现了该类。

public class CircularPane extends Pane {
    private long degreese = 0;
    private long increment;
    @Override
    protected void layoutChildren() {
        final int radius = 250;
        final double increment = 360 / getChildren().size();
        double degreese = 0;
        for (Node node : getChildren()) {
            double x = radius * Math.cos(Math.toRadians(degreese)) + getWidth() / 2;
            double y = radius * Math.sin(Math.toRadians(degreese)) + getHeight() / 2;
            layoutInArea(node, x - node.getBoundsInLocal().getWidth() / 2, y - node.getBoundsInLocal().getHeight() / 2, getWidth(), getHeight(), 0.0, HPos.LEFT, VPos.TOP); …
Run Code Online (Sandbox Code Playgroud)

java javafx

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