gpt4 book ai didi

第二屏幕上的 javafx 全屏

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:07:40 24 4
gpt4 key购买 nike

对于我的生活,我似乎无法获得这方面的帮助。我有一个 JavaFX 屏幕,我正试图在我的第二台显示器上显示全屏。我根据其他建议尝试了以下方法,但无济于事。我知道坐标是正确的,但它在我的主显示器上保持全屏显示。请帮忙。

if (mainSet.getBoolean("fullScr", false)) {
int count = mainSet.getInt("MonSel", 0);
if (count > 0) {
int i = 0;
for (Screen screen: Screen.getScreens()) {
if (count == i) {
Rectangle2D bounds = screen.getBounds();
primaryStage.setX(bounds.getMinX());
System.out.println(bounds.getMinX());
System.out.println(bounds.getMinY());
primaryStage.setY(bounds.getMinY());
}
i++;
}
}
primaryStage.setFullScreen(true);
}

第一个 if 检查首选项以查看是否设置了全屏。第二个 if 查看是否选择了第一个监视器之外的另一个监视器。它是 1,所以它应该是第二台显示器。该程序循环遍历所有屏幕并尝试移动该程序,然后将全屏显示。我知道坐标是相同的但没有骰子,它仍然在主屏幕上全屏显示。请帮忙。

最佳答案

我不知道我是否真正理解你的问题,但如果你有两个屏幕,为什么要循环显示屏幕?为什么不直接在 ObservableList 的位置二/索引之一使用与屏幕关联的信息?我正在发布一个示例应用程序,演示如何在第二台显示器上显示全屏。

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Screen;
import javafx.stage.Stage;

/**
*
* @author blj0011
*/
public class JavaFXApplication257 extends Application
{

@Override
public void start(Stage primaryStage)
{
ObservableList<Screen> screens = Screen.getScreens();//Get list of Screens
Button btn = new Button();
btn.setText("Full Screen - Screen 1");
btn.setOnAction((ActionEvent event) -> {
Rectangle2D bounds = screens.get(0).getVisualBounds();
primaryStage.setX(bounds.getMinX());
primaryStage.setY(bounds.getMinY());
primaryStage.setFullScreen(true);
//primaryStage.setWidth(bounds.getWidth());
//primaryStage.setHeight(bounds.getHeight());
});

Button btn2 = new Button();
btn2.setText("Full Screen - Screen 2");
btn2.setOnAction((ActionEvent event) -> {
if (screens.size() > 0) {
Rectangle2D bounds = screens.get(1).getVisualBounds();
primaryStage.setX(bounds.getMinX());
primaryStage.setY(bounds.getMinY());
primaryStage.setFullScreen(true);
//primaryStage.setWidth(bounds.getWidth());
//primaryStage.setHeight(bounds.getHeight());
}
});

StackPane root = new StackPane();
root.getChildren().add(new VBox(btn, btn2));

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}

}

关于第二屏幕上的 javafx 全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52269377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com