Scrollbar in JAVAFX - java

Just wondering if anyone know how to implement a vertical scrollbar that spans the entire scene in JavaFX? Been trying to figure it out for a few days now and I just can't seem to figure it out.

If you mean make it your root you can do it like this
Stage stage = new Stage();
ScrollPane pane = new ScrollPane();
TextField yourcontent = new TextField("this is an example");
pane.setContent(yourcontent);
pane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
Scene scene = new Scene(pane,300,300);
stage.setScene(scene);
stage.showAndWait();
and then put the rest of your content in it via setContent();

Related

How to Scale a datePicker in java using a DatePickerSkin

What I'm trying to do is to scale a popup content of a javafx.scene.control.DatePicker using javafx.scene.control.skin.DatePickerSkin to add an scale,
DatePickerSkin skin = new DatePickerSkin(datePickerFrom);
skin.getPopupContent().getTransforms().add(new Scale(1.5,1.5,0,0));
By using this code, all I got is
I didn't found a way to input a skin instead of DatePicker and if there is a way to add a scale directly to the Datepicker
In this software, all items are getting scaled for the display sizes
in case you wanted the detailed code, I created this,
Stage stage = new Stage();
DatePicker datePicker = new DatePicker();
DatePickerSkin datePickerSkin = new DatePickerSkin(datePicker);
datePickerSkin.getPopupContent().getTransforms().add(new Scale(1.5,1.5,0,0));
Pane pane = new Pane();
stage.setWidth(300);
stage.setHeight(100);
pane.getChildren().addAll(datePicker);
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.show();

Customizing primaryStage title : centered with icon

I'm working on a school project in Java FX, I'd like to add an icon next to my primarystage title and center the title, just like the one in the picture. I have looked around in the javadoc for Stage but i can only find the setTitle() method. Here is a link to what i'd like to do :
You can set your stage to undecorated, set your scene root to a border pane and create your own custom top bar.
BorderPane root = new BorderPane();
root.setTop(new Pane(bb, label));
Scene scene = new Scene(root, 400, 400);
ButtonBar topBar = new ButtonBar(… insert buttons in here....);
// eg: Button b = new Button("X); b.setOnAction(e->{stage.close();});
root.setTop(topBar);
stage.initStyle(StageStyle.UNDECORATED);

Reusing the same buttons for a different scene in JavaFX

I am trying to reuse my buttons after changing scene.
HBox area = new HBox();
area.getChildren().addAll(homeButton, loadAPubButton);
area.setSpacing(20);
area.setAlignment(Pos.CENTER);
// Home Scene
BorderPane homePane = new BorderPane();
homePane = setupHomeScene(homePane);
homePane.setTop(area);
home = new Scene(homePane,1280,960);
// Load a Pub Crawl Scene
BorderPane loadPane = new BorderPane();
loadPane = loadPubCrawl(loadPane);
loadPane.setTop(area);
loadPub = new Scene(loadPane,1280,960);
This code will use the same HBox on two different scenes however it doesn't seem to work. I am really stuck and any help would be much appreciated.

Why image disappears from titled pane after mouse event?

I have a titled pane, and I'm displaying an image in this pane, but the image is very big so I resize it, to fit the pane. Since the image becomes smaller, the user might want to view it in original size, so I implemented a method on mouse click opening the original image in new bigger window.
imgViewPicture.setFitWidth(titledPanePicture.getPrefWidth());
imgViewPicture.setPreserveRatio(true);
imgViewPicture.setSmooth(true);
imgViewPicture.setCache(true);
titledPanePicture.setContent(imgViewPicture);
The problem is, when I click on titledPanePicture the small image disappears, its content is cleared. Why? For the solution I added a reloading of the content on mouseclick event. But I dont like it, I think the content should stay the same for titledPanePicture.
Here is my mouseclick event:
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
Group root = new Group();
Scene scene = new Scene(root);
scene.setFill(Color.BLACK);
HBox box = new HBox();
imgViewPicture.setFitWidth(0);
box.getChildren().add(imgViewPicture);
root.getChildren().add(box); // before tPane
stage.setTitle("Picture Original Size");
stage.setScene(scene);
stage.sizeToScene();
stage.show();
reloadContentofTitledPane(); // This line is the fix but I find it unnecessary
Tips would be appreciated.
You seem to use the same ImageView in both scenes. However a Node can only be placed at a single place in a single scene graph.
Create a new node for your new Scene.
ImageView newImageView = new ImageView(imgViewPicture.getImage());
...
box.getChildren().add(newImageView);

Binding BorderPane and Frame Height and Width

I am using JavaFX 2 in Netbeans. How do I get the width and height of an element to adjust when the Frame is resized? Here is my layout:
Stage stage = new Stage();
stage.setTitle("Hello World");
final Group root = new Group();
Scene scene = new Scene(root);
BorderPane border = new BorderPane();
border.setPrefWidth(stage.getWidth());
border.setPrefHeight(stage.getHeight());
HBox outerHBox = new HBox();
border.setCenter(outerHBox);
root.getChildren().add(border);
stage.setScene(scene);
After some more research
I found where this has been done before http://java.dzone.com/articles/setting-stage-javafx-sdk but it is in an older FX (very different from JavaFX 2). I am having trouble translating it. Looks like I should be using binding? I've never used binding before and I've barely used FX.
Whats the best way to accomplish this?
Not all Node classes enable resizing. The Group class is one of these. You'll understand this when calling isResizable() on your root object. Use instead a subclass of Region e.g. BorderPane as your root.
Stage stage = new Stage();
stage.setTitle("Hello World");
final BorderPane border = new BorderPane();
Scene scene = new Scene(border);
Button button = new Button("test");
HBox outerHBox = new HBox();
outerHBox.getChildren().add(button);
outerHBox.setAlignment(Pos.CENTER);
border.setCenter(outerHBox);
stage.setScene(scene);
Your example should work, now.

Categories