我的目标是创建一个JavaFX应用程序,就像一个小部件(alwaysOnTop),但它也减少了其他外部应用程序的可用空间。
您可以看到它像一个新的Windows工具栏:如果我以全屏模式打开浏览器,我希望我的"工具栏"在浏览器旁边可见,始终可见,但没有重叠。
此工具栏将采用所有屏幕的高度,并粘在屏幕的左侧或右侧。
1)JavaFX可以做到这一点吗?(或者在JavaFX中集成了一些Swing)
2)我该怎么做?或者我在哪里可以找到一些文档?(其中一个难点是我找不到我想做的事情的关键词,可能是因为我缺乏英语词汇)
3)这是可互操作的吗?(Windows,MacOS,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();
希望这是你想要的...