I need to reproduce this image in javafx see Interface
the way i approached this interface is as follows :
Created a BorderPane layout
BorderPane.TOP : set inside it a HBOX layout for the menu on top
BorderPane.Center : set inside it a Pane Layout which contains the the planets ( see image again )
this is end result i got click to see image
Clearly i am doing something wrong here , please clarify to me
this interface is supposed to be FULLSCREEN and responsive
i tried doing the following Controller Code:
public class HomeController implements Initializable
{
#FXML
private BorderPane borderPane;
public void initialize(URL location, ResourceBundle resources) {
// responsivity
Screen screen = Screen.getPrimary();
Rectangle2D bounds = screen.getVisualBounds();
Stage stage = Entry.getMainStage();
stage.setX(bounds.getMinX());
stage.setY(bounds.getMinY());
stage.setWidth(bounds.getWidth());
stage.setHeight(bounds.getHeight());
// this code gives an error
borderPane.setBottom(null);
borderPane.setLeft(null);
borderPane.setRight(null);
}
}
Related
I am troubleshooting my deployment on Android (not yet tested on iOS also).
I have a simple SplashView class that just centers an image.
public class MySplashView extends SplashView {
public MySplashView(String nextView) {
super(nextView);
Image image = new Image(MySplashView.class.getResourceAsStream("/my_logo.jpg"));
ImageView imageView = new ImageView(image);
imageView.setFitWidth(AppManager.getInstance().getGlassPane().getWidth() * .75);
imageView.setPreserveRatio(true);
StackPane stackPane = new StackPane(imageView);
super.setCenter(stackPane);
}
I've tried to declare this SplashView as soon as possible in the Application's workflow.
public class MyApplication extends Application {
#Override
public void init() {
AppManager.getInstance().addViewFactory(SPLASH_VIEW, () -> new MySplashView("loginView"));
}
Before introducing this SplashView, the order I'd see at application start would be:
Black Screen
Login View
Now I see:
Black Screen
Splash View
Login View
What more/else can I do so to stop showing the User an initial black screen?
I have a split pane with a initial divider position set to 0.2, the problem is that after running the application the position is changed to 0.5, I read that it is due to stage.setMaximized(true);
I checked this question, but the answers imply that the current split pane and the main stage are in the same class, but in my case, I have to work in a controller class.
I tried to add a listener to the stage showing property Main.getStage().showingProperty().addListener(...) in the initialize() method, but it doesn't work, it says stage is null, I guess it's because initialize() runs before Main.start()
So how can I make my split pane start with a fixed divider position?
Thanks!
EDIT :
I made a simple example to expose my problem :
Main
#Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader=new FXMLLoader(getClass().getResource("views/test.fxml"));
mainStage=primaryStage;
mainStage.setScene(new Scene(loader.load()));
mainStage.show();
Controller_Test ct=loader.getController();
System.out.println("Main:"+ct.sp.getDividerPositions()[0]);
ct.getDividerPos();
}
Controller_Test
#FXML
public SplitPane sp;
#FXML
public void initialize() {
System.out.println("Initialize:"+sp.getDividerPositions()[0]);
}
public void getDividerPos(){
System.out.println("Method:"+sp.getDividerPositions()[0]);
}
Now I set the split pane divider at 1, which means the second pane should not show, I run the application and here is the result :
Okay for this one, the divider is at 1, so only one pane is showing, now I will maximize the window :
The divider position clearly changed.
If you read the code I provide previously, you can see 3 print lines as checkpoints, here is their output after running the application :
Initialize:1.0
Main:0.9933110367892977
Method:0.9933110367892977
Thanks!
Firstly, sorry for my English. I hope, you unterstand it.
Last Month I started developing a little programm with FXML/ JavaFX.
I have two screens, and I'm switching between them. This is not the problem.
The problem is: On one Screen i have a listview, where i can choose an item. When i have chosen an item, i want to open a new tab on the other screen with the content of the item. Therefore, i have to click on a button.
When i have chosen an item, i can print out the selected item, but how do I open a new tab on the other screen. Both Screens a two different FXML and are activited from the controller. How can I add a Tab, although loading fxml?
public class Controller{
#FXML
private ListView<String> lv;
#FXML
private Button check;
#FXML
public void projectview (Event e3) throws Exception{
Stage stage = null;
Parent root = null;
if(e3.getSource()==check){
//Check is the declaration for the Button on the screen with the listview
String projectview= lv.getSelectionModel().getSelectedItem();
stage = (Stage) check.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FXML1.fxml"));
//Here I want to add a tab in FXML1.fxml
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
}
If something is missing or not clear, please ask. I read other similar questions, but i don't know, what to do.
Thanks for help
I've a tabview that contains a scrollPane, and a scrolPane contains nodes.
I added a button fit, i want when i click in this button the content of the scrollpane will be centered, I dont know how to do this
#FXML protected void onFitClicked(ActionEvent event)
{
//calling the method that centers the content of the scrollpane
fit();
}
that's what i've done until now .. :( i'll be happy for any help
public void fit()
{
m_scrollPane.setFitToWidth(true);
m_scrollPane.setFitToHeight(true);
}
Try
m_scrollPane.setHvalue(0.5);
m_scrollPane.setVvalue(0.5);
i was searching in google for hours and i still cant find the right answer, so i have a last chance to come here and ask.
i'm making school year JAVA FX project. I'm using NetBeans.
I have a point that i can see on the application i have. The problem is: I would like to have a big map (background) and I need to be able to move with my view. For example move by 50 to the right (x).
I have Application where I use Stage, Scene, StackPane.
I heard something about Dimensions in Java, but i can't use it in javafx application. Is there something similar, what can I use in my Application?
Thank you very much.
What I think you are asking for is a Scene with a map (represented as an Image) in the background and controls layered on top of the map to allow interaction with the map at certain positions. Your question is a little unclear, so I'm not exactly sure if that is what you are asking.
If so, here is some sample code to implement that.
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.*;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
/** Constructs a scene with a pannable Map background. */
public class PannableView extends Application {
private Image backgroundImage;
#Override public void init() {
backgroundImage = new Image("https://www.narniaweb.com/wp-content/uploads/2009/08/NarniaMap.jpg");
}
#Override public void start(Stage stage) {
stage.setTitle("Drag the mouse to pan the map");
// construct the scene contents over a stacked background.
StackPane layout = new StackPane();
layout.getChildren().setAll(
new ImageView(backgroundImage),
createKillButton()
);
// wrap the scene contents in a pannable scroll pane.
ScrollPane scroll = createScrollPane(layout);
// show the scene.
Scene scene = new Scene(scroll);
stage.setScene(scene);
stage.show();
// bind the preferred size of the scroll area to the size of the scene.
scroll.prefWidthProperty().bind(scene.widthProperty());
scroll.prefHeightProperty().bind(scene.widthProperty());
// center the scroll contents.
scroll.setHvalue(scroll.getHmin() + (scroll.getHmax() - scroll.getHmin()) / 2);
scroll.setVvalue(scroll.getVmin() + (scroll.getVmax() - scroll.getVmin()) / 2);
}
/** #return a control to place on the scene. */
private Button createKillButton() {
final Button killButton = new Button("Kill the evil witch");
killButton.setStyle("-fx-base: firebrick;");
killButton.setTranslateX(65);
killButton.setTranslateY(-130);
killButton.setOnAction(new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent t) {
killButton.setStyle("-fx-base: forestgreen;");
killButton.setText("Ding-Dong! The Witch is Dead");
}
});
return killButton;
}
/** #return a ScrollPane which scrolls the layout. */
private ScrollPane createScrollPane(Pane layout) {
ScrollPane scroll = new ScrollPane();
scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scroll.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scroll.setPannable(true);
scroll.setPrefSize(800, 600);
scroll.setContent(layout);
return scroll;
}
public static void main(String[] args) { launch(args); }
}
For the example use the mouse (or probably touch commands or trackpad scroll gestures - though I haven't a touch screen or trackpad to test it) to drag the map around. Click on the button to "Kill the evil witch".
The solution works by:
Creating an ImageView to hold the background map.
Constructing the scene contents in a StackPane over the stacked background ImageView.
Wrapping the scene in a ScrollPane bound to the scene's size.
Setting properties on the ScrollPane to make it pannable.