gpt4 book ai didi

JavaFX : How to reduce window fullscreen of other application

转载 作者:太空宇宙 更新时间:2023-11-04 14:04:54 26 4
gpt4 key购买 nike

我的目标是创建一个像 Widget (alwaysOnTop) 一样运行的 JavaFX 应用程序,但它也会减少其他外部应用程序的可用空间。

您可以看到它就像一个新的 Windows 工具栏:如果我以全屏模式打开浏览器,我希望我的“工具栏”在浏览器旁边可见,始终可见,但没有重叠。

此工具栏将占据整个屏幕的高度并粘贴到屏幕的左侧或右侧。

1) JavaFX 可以做到这一点吗? (或者在 JavaFX 中集成一些 Swing)

2)我该怎么做?或者我在哪里可以找到一些文档? (困难之一是我找不到我想做的事情的关键词,可能是因为我缺乏英语词汇)

3) 这可以互操作吗? (Windows、MacO、Linux...)

4)是否有其他应用程序可以实现此技巧? (有人告诉我VLC可以做到这一点,但我没有找到参数)

如果我的描述不清楚,我会编辑晦涩的部分:)

最佳答案

先生;

您: “此工具栏将占据整个屏幕的高度并粘贴到屏幕的左侧或右侧”

我:使用Screen

你: “JavaFX 可以做到这一点吗?(或者 JavaFX 中的一些 Swing 集成)”

我:是的

你: “我该怎么做?或者我在哪里可以找到一些文档?(其中一个困难是我找不到我想做的事情的关键词,可能是因为我缺乏英语词汇)”

我:这里是代码示例

//create two stages
Stage toolbar = new Stage(), main = new Stage();
//creating a chunk here to fill up our 'main'
AnchorPane a = new AnchorPane();
WebView wv = new WebView();
Label l = new Label("Loading url");
wv.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {

@Override
public void changed(ObservableValue<? extends State> arg0,
State arg1, State arg2) {
if(arg2.equals(State.RUNNING)){
l.setText("LOADING");
}else if(arg2.equals(State.SUCCEEDED)){
l.setText("DONE");
}
}
});
wv.getEngine().load("http://stackoverflow.com/users/3894351/elltz");
a.autosize();
a.getChildren().addAll(wv,l);
Scene scene = new Scene(a,500,500);
main.setScene(scene);
main.show();

//creating a chunk to fill up 'toolbar'
TreeItem<String> treeItemRoot1 = new TreeItem<> ("StackOverflow Users");
TreeItem<String> nodeItemA = new TreeItem<>("Elites");
TreeItem<String> nodeItemB = new TreeItem<>("Rookies");
treeItemRoot1.getChildren().addAll(nodeItemA, nodeItemB);
nodeItemA.setExpanded(true);
nodeItemB.setExpanded(true);
TreeItem<String> nodeItemA1 = new TreeItem<>("Jon Skeet");
TreeItem<String> nodeItemA2 = new TreeItem<>("jwelsea");
TreeItem<String> nodeItemA3 = new TreeItem<>("James D");
nodeItemA.getChildren().addAll(nodeItemA1, nodeItemA2, nodeItemA3);
TreeItem<String> nodeItemB1 = new TreeItem<>("Elltz");
TreeItem<String> nodeItemB2 = new TreeItem<>("Sybb");
nodeItemB.getChildren().addAll(nodeItemB1, nodeItemB2);
TreeView<String> treeView = new TreeView<>(treeItemRoot1);
treeView.setShowRoot(false);
// starting of the toolbar alignments
toolbar.initModality(Modality.NONE); // with this function, i dont quite recall but all
//you can say is Modality.NONE, means do not override focus from another window
toolbar.setScene(new Scene(treeView,120,(Screen.getPrimary().getVisualBounds().getHeight()-20)));
// the getPrimary gets the default screen or monitor to your system
//so in short i get the height of it then - n; depends on how your screen & margins kinda stuff
toolbar.setMaxWidth(125); //to prevent excessive re-sizing; you could change to your likeness
toolbar.setMinWidth(120); //to prevent excessive re-sizing; you could change to your likeness
toolbar.setX((Screen.getPrimary().getVisualBounds().getMaxX()-130));
// this function above positions your scene at the (widith_of_entire_
//screen - the size of the stage which is toolbar - 10); so with this my
// calculations it will be set perfectly at the right side. the 10 has here
// stands for margins or stuff like that. but if you want the left side,
// you just use the line Screen.getPrimary().getVisualBounds().getMinX();
// you do not need to subtract because you start counting from 0 on your left
toolbar.setY((Screen.getPrimary().getVisualBounds().getMinY()));
// this function above positions the stage vertically, it starts counting
// from 0 at the top, if you wanted to position it somewhere at the bottom
// then you do the minus(-) things
toolbar.show();
new Thread(new Runnable() {
@Override
public void run() {
while(true){
try {
Thread.sleep(100); //buy little millieseconds
} catch (InterruptedException e) {}

Platform.runLater(()->{
toolbar.toFront();
//bring your UI on top of everyone
});
}

}
}).start();

希望这是你想要的......

关于JavaFX : How to reduce window fullscreen of other application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28969215/

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