Reputation: 21
I aim to create a JavaFX application acting like a Widget (alwaysOnTop) but which also reduces available space for other outside applications.
You could see that like a new Windows toolbar : if I open my browser in fullscreen mode, I would like my "toolbar" to be visible beside the browser, always visible, but with no overlap.
This toolbar would take all screen's height and be glued to left or right side of the screen.
1) Is that possible with JavaFX ? (Or with some Swing integration in JavaFX)
2) How could I do that ? Or where could I find some documentation ? (One of the difficulty is that I can not find a key word for what i want to do, may be due to my lack of english vocabulary)
3) Is this interoperable ? (Windows, MacOs, Linux...)
4) Is there other application that can achieve this trick ? (Some told me that VLC could do that but I did not found the parameter)
If I am unclear in my description, I will edit obscure parts :)
Upvotes: 1
Views: 814
Reputation: 10869
Sir;
you: "This toolbar would take all screen's height and be glued to left or right side of the screen"
me: use Screen
class
you: " Is that possible with JavaFX ? (Or with some Swing integration in JavaFX)"
me: yes
you: "How could I do that ? Or where could I find some documentation ? (One of the difficulty is that I can not find a key word for what i want to do, may be due to my lack of english vocabulary)"
me: here code sample
//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();
HOPE its what you wanted...
Upvotes: 0