标签: javafx

JavaFX:在splashScreen中使用Indeterminate Progressbar

我有一个闪屏:

闪屏 我需要有进度条的动画(Indeterminate),但它不起作用.

这可能是因为我的线程在我的initilize方法中运行.

public class splashscreenController implements Initializable {
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    new SplashScreen().run();
  }

  class SplashScreen extends Task {
    @Override
    public Object call() {

        Platform.runLater(new Runnable() {
            @Override
            public void run()
                Parent root = null;
                try {
                    Thread.sleep(3000);
                    root = FXMLLoader.load(getClass().getResource("../gui/NewUI.fxml"));
                } catch (InterruptedException | IOException e) {
                    e.printStackTrace();
                }
                Stage stage = new Stage();
                stage.initStyle(StageStyle.UNDECORATED);

                assert root != null;
                Scene scene = new Scene(root, 1280, 720);
                stage.setScene(scene);
                stage.show();
                MainJavaFx.setPrimaryStage(stage);
                ((Stage) panParent.getScene().getWindow()).close();
            }
        }); …
Run Code Online (Sandbox Code Playgroud)

java javafx splash-screen javafx-8

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

AnchorPane元素忽略鼠标单击

我初始化了一些元素而不是我的Anchor窗格:

AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load(), menuLoader.load(), buttonLoader.load());
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试单击MenuBar或列表视图时,它不起作用.例如,在这种情况下,我可以单击按钮(可能),因为它是我在AnchorPane构造函数中初始化的最后一个元素.我无法使用BorderPane或任何其他布局,因此我需要找到具有此配置的解决方案.这些是我的fxml文件:

list.fxml

<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">
<children>
    <AnchorPane> 
        <children>
            <ListView fx:id="listView" layoutX="1.0" layoutY="31.0" prefHeight="371.0" prefWidth="239.0" />
        </children>
    </AnchorPane> 
</children>
Run Code Online (Sandbox Code Playgroud)

menuBar.fxml

<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.MenuBarController">
<children>
    <AnchorPane> 
        <children>
            <MenuBar fx:id="menuBar" layoutX="0.0" layoutY="0.0">
                <menus>
                    <Menu text="File">
                        <items>
                            <MenuItem onAction="#elimina" text="Elimina" />
                        </items>
                    </Menu>
                    <Menu text="Cambia Account">
                        <items>
                            <MenuItem fx:id="email1" text="filippo@hotmail.it" />
                            <MenuItem fx:id="email2" text="giancarlo@yahoo.it" />
                            <MenuItem fx:id="email3" text="alessandro@gmail.it" />
                        </items>
                    </Menu>
                </menus>
            </MenuBar>
        </children>
    </AnchorPane>
</children>
Run Code Online (Sandbox Code Playgroud)

textArea.fxml

<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.TextAreaController">
<children> …
Run Code Online (Sandbox Code Playgroud)

java javafx fxml

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

围绕共同中心旋转一组矩形

我有一些矩形,我逐个指定旋转((javafx.scene.shape.Rectangle) shape).rotateProperty().bind(rotate); 例如,45度 在此输入图像描述

在此输入图像描述

我的矩形围绕其中心旋转.请告诉我如何让敌人围绕他们的共同中心做几个直角. 在此输入图像描述

得到这样的东西 在此输入图像描述

this.rotate.addListener((obs, old, fresh) -> {
for (VObject vObject : children ) {
vObject.rotate.set(this.rotate.get());
}
});
这是我添加旋转的方式.如何指定角度

更新:我使用了下面的建议,现在我为每个矩形单独设置旋转.(选择仍然有点不对)

            this.rotate.addListener((obs, old, fresh) -> {
            Rotate groupRotate = new Rotate(rotate.get(),
                    this.x.getValue().doubleValue() + this.width.getValue().doubleValue() / 2 ,
                    this.y.getValue().doubleValue() + this.height.getValue().doubleValue() / 2);
            for (VObject vObject : children ) {
                vObject.getShape().getTransforms().clear();
                vObject.getShape().getTransforms().add(groupRotate);
            }
        });
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在此输入图像描述 但现在轴也会根据旋转而旋转.

在此输入图像描述

我可以在不转动坐标轴的情况下将旋转设置为矩形吗?

java javafx

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

应用程序start()方法中的Javafx绑定抛出异常

UnsupportedOperationExceptionBindings.bindContent()将对象绑定到时抛出TableView。为什么?如何解决这个问题?

我正在使用Java 8 update181。

 Exception in Application start method java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
 Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
 Caused by: java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(AbstractList.java:161)
    at java.util.AbstractList$Itr.remove(AbstractList.java:374)
    at java.util.AbstractList.removeRange(AbstractList.java:571)
    at java.util.AbstractList.clear(AbstractList.java:234)
    at com.sun.javafx.binding.ContentBinding.bind(ContentBinding.java:55)
    at javafx.beans.binding.Bindings.bindContent(Bindings.java:1020)
    at problem_bind.Main.start(Main.java:42)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294) …
Run Code Online (Sandbox Code Playgroud)

binding javafx tableview invocationtargetexception unsupportedoperation

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

按钮之间有无法解释的空间

我做运动有问题。场景中的第一个按钮和第二个按钮之间有无法解释的空间。我更改了按钮的位置,但第一个按钮与第二个按钮之间有一个空格。是什么原因造成的?如何缩小此空间? https://imgur.com/hYolYE2

    public void start(Stage myStage) {

        GridPane myPane = new GridPane();
        myPane.setPadding(new Insets(10, 10, 10, 10));
        myPane.setHgap(10);
        myPane.setVgap(10);

        Button btn1 = new Button("Computer Scinence");
        Button btn2 = new Button("Chemistry");
        Button btn3 = new Button("Arts");

        DrawText txt1 = new DrawText("Computer Scince","Times Roman",FontWeight.BOLD,FontPosture.ITALIC,20,Color.GREEN);
        DrawText txt2 = new DrawText("Chemistry","Times Roman",FontWeight.BOLD,FontPosture.ITALIC,20,Color.BLUE);
        DrawText txt3 = new DrawText("Arts","Times Roman",FontWeight.BOLD,FontPosture.ITALIC,20,Color.YELLOW);

        GridPane.setConstraints(btn1,0,1);
        GridPane.setConstraints(btn2,1,1);
        GridPane.setConstraints(btn3,2,1);
        GridPane.setConstraints(txt1,0,2);
        GridPane.setConstraints(txt2,0,3);
        GridPane.setConstraints(txt3,0,4);

        myPane.getChildren().addAll(btn1,btn2,btn3,txt1,txt2,txt3);

        Scene myScene = new Scene(myPane,350,190);        
        myStage.setScene(myScene);        
        myStage.setTitle("Exercise 3_3");        
        myStage.show();
    }

Run Code Online (Sandbox Code Playgroud)

java javafx

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

在对象初始化块内使用花括号

为什么bind()仅在将范围大括号内设置时该函数存在?

public void initialize() {

    inputsAreFull = new BooleanBinding() {
        {
            bind();
        }

        @Override
        protected boolean computeValue() {
            return false;
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

IntelliJ会自动建议bind()在花括号内使用,但是在花括号外不存在该功能吗?

这行不通:

public void initialize() {

    inputsAreFull = new BooleanBinding() {

        bind();

        @Override
        protected boolean computeValue() {
            return false;
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

java javafx

0
推荐指数
2
解决办法
52
查看次数

How to limit how much the user can resize a JavaFX window?

I am looking for ways to limit how much a user can resize the main window of my application, without preventing resizing completely. Specifically, I want to set minimum width and height for the window, and you'd think minWidth and minHeight would achieve this, but apparently they do not.

The root element of my window (declared in fxml) looks like this:

<VBox xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml"
      fx:controller="com.my.module.FXMLController"
      minWidth="400.0">
    <!-- ... -->
</VBox>
Run Code Online (Sandbox Code Playgroud)

But all that minWidth seems to be doing is setting …

java user-interface resize javafx fxml

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

如何在javafx textarea中显示计数查询的所有行?它只显示第一行而不是两行

我希望count和groupby(sqlite)sql查询的两行显示在文本区域中,但是它仅显示第一行。

当我将conn.close()语句放置在“ while”块之外时,它仅显示第二行,而忽略第一行

@FXML
private void viewResult(ActionEvent event)
{
    try
    {
        Connection conn = dbConnection.getConnection();
        Statement resultStmt = conn.createStatement();   
        ResultSet rs = resultStmt.executeQuery("select candidate, count(candidate) from voteResult group by candidate");
        while (rs.next()) {
            String news = rs.getString(1)+" "+rs.getString(2);
            this.result.setText(news);
            conn.close();
        }
    }
    catch (SQLException e)
    {
        System.err.println("Error " + e);
    }

}
Run Code Online (Sandbox Code Playgroud)

预期结果应如下所示:

JOSEPH THANKGOD 4
ORJI DANIEL 1
Run Code Online (Sandbox Code Playgroud)

javafx

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

即使数学正确,矩形也不跟随鼠标

我有一个基本的寻路程序,我希望矩形跟随鼠标移动。我正在使用这种特定的寻路方法,因为我想在将来对其进行扩展。我有2种方法:一种获取2个矩形之间的角度,另一种以x角度移动矩形。出于某种原因,该矩形仅在其前面时跟随我的鼠标,而不是在它后面时。

如果我不再Math.abs使用我的角度方法,问题仍然存在。

以下是我的两个基本课程。

PathfindingTest.java,这是主类,它初始化所有内容:

package pathfindingtest;

import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 *
 * @author Preston Tang
 */
public class PathfindingTest extends Application {

    private final long[] frameTimes = new long[100];
    private int frameTimeIndex = 0;
    private boolean arrayFilled = false;

    private double mouseX, mouseY;

    @Override
    public void start(Stage stage) {
        Pane base = new Pane();
        base.setStyle("-fx-background-color: rgb(" + 40 + "," + 40 + ", …
Run Code Online (Sandbox Code Playgroud)

java graphics 2d javafx path-finding

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

如何从根文件夹设置JavaFx中标签的字体?

我已将项目的字体存储在*>root*目录中的*>font*目录中。

我尝试使用以下代码:

public class NewController implements Initializable {

        @FXML
        private Label titleLabel;

        @Override
        public void initialize(URL url, ResourceBundle rb) {
            titleLabel.setFont(Font.loadFont("fonts/Archivo-Regular.ttf", 30));
        }
    }  
Run Code Online (Sandbox Code Playgroud)

但是它不能设置字体。

fonts javafx

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