我的目标是创建一个像Widget(alwaysOnTop)一样的JavaFX应用程序,但它也减少了其他外部应用程序的可用空间。
你可以看到像新的Windows工具栏一样:如果我以全屏模式打开浏览器,我希望我的“工具栏”在浏览器旁边可见,始终可见,但没有重叠。
此工具栏将占据屏幕的所有高度,并粘贴在屏幕的左侧或右侧。
1)JavaFX可以实现吗? (或者在JavaFX中使用一些Swing集成)
2)我怎么能这样做?或者我在哪里可以找到一些文档? (其中一个难点是我找不到一个关键词我想做什么,可能是因为我缺乏英语词汇)
3)这可以互操作吗? (Windows,MacOs,Linux ......)
4)是否有其他应用可以实现这一诀窍? (有些人告诉我,VLC可以这样做,但我没有找到参数)
如果我在描述中不清楚,我将编辑模糊的部分:)
答案 0 :(得分:0)
爵士;
你: "此工具栏将占据所有屏幕的高度并粘贴到屏幕的左侧或右侧"
me:使用Screen
类
你: "这可能与JavaFX有关吗? (或者在JavaFX中使用一些Swing集成)"
我:是
你: "我怎么能这样做?或者我在哪里可以找到一些文档? (困难之一是我无法找到我想做的关键词,可能是因为我缺乏英语词汇)"
me:此处代码示例
//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();
希望你想要的东西......