多监视器JavaFX的显示问题
我的应用程序按预期运行,但运行时会出现显示问题。当它运行时,java窗口会弹出正确的窗口大小,但是由于某些原因,窗口中的控件非常大。我能够解决这个问题并让它们以正常大小显示的唯一方法是,我将窗口拖到另一个显示器上,将其放下(此时超大的控件会移动一点),然后将其拖回笔记本电脑显示器。然后控件收缩并正确显示 但是,如果我把它拖回到我的另一个监视器上,控件会再次爆炸 我使用的是运行在MacOSX 10.10.3上的IntelliJ 14和Scene Builder 2.0 FXML文件:多监视器JavaFX的显示问题,java,intellij-idea,javafx,fxml,multiple-monitors,Java,Intellij Idea,Javafx,Fxml,Multiple Monitors,我的应用程序按预期运行,但运行时会出现显示问题。当它运行时,java窗口会弹出正确的窗口大小,但是由于某些原因,窗口中的控件非常大。我能够解决这个问题并让它们以正常大小显示的唯一方法是,我将窗口拖到另一个显示器上,将其放下(此时超大的控件会移动一点),然后将其拖回笔记本电脑显示器。然后控件收缩并正确显示 但是,如果我把它拖回到我的另一个监视器上,控件会再次爆炸 我使用的是运行在MacOSX 10.10.3上的IntelliJ 14和Scene Builder 2.0 FXML文件: <?x
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="332.0" prefWidth="404.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="408.0" minWidth="10.0" prefWidth="408.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button id="btnTest" contentDisplay="CENTER" mnemonicParsing="false" onAction="#foo" prefHeight="74.0" prefWidth="275.0" text="Generate Encryption Key" GridPane.halignment="CENTER">
<GridPane.margin>
<Insets />
</GridPane.margin>
</Button>
<Label fx:id="lblTop" alignment="TOP_CENTER" contentDisplay="TOP" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">
<GridPane.margin>
<Insets top="35.0" />
</GridPane.margin>
</Label>
<TextField fx:id="txtKey" alignment="CENTER" editable="false" GridPane.rowIndex="1" />
</children>
</GridPane>
UPADATE:
这个问题似乎是一个智能问题。我决定尝试构建我的应用程序,在我运行JAR之后,它工作得非常好。应用程序的逻辑功能正常,上述显示问题不再出现
在监视器之间移动时,它确实会稍微调整大小抖动,但它从不错误地显示元素
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import java.beans.EventHandler;
import java.util.ResourceBundle;
import java.util.Random;
import java.awt.*;
import java.net.URL;
public class Controller implements Initializable{
@FXML
private TextField txtKey;
@FXML
private Label lblTop;
@FXML
private Button btnButton;
Random rnd = new Random();
private char[] pool = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'};
@Override
public void initialize(URL fxmlFileLocation, ResourceBundle resources){
assert btnButton != null : "fx:id=\"txtKey\" was not injected: check your FXML file 'sample.fxml'.";
}
public void foo (ActionEvent actionEvent){
String key = "";
for (int i = 0; i < 32; i++){
key = key + pool[rnd.nextInt(36)];
}
lblTop.setText("Your Encryption Key is:");
txtKey.setText(key);
}
}
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Encryption Key Generator");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}