Java Fx scene change - javafx-2

I am using Java FX for a desktop application.Can i change a scene inside one scene?First scene has an anchorpane inside which one another anchor pane is included.Can i change the scene in the second anchorpane?

just load AnchorPane inside Anchorpane. no need of creatinig new scene..
AnchorPane main=new AnchorPane();
AnchorPane sub=new AnchorPane();
sub.getChildren().add(btn);
main.getChildren().add(sub);
Scene is super class to Node so i think its impossible to load scene inside Scene.
however u can switch scenes in a stage.

Related

Move view from top to bottom continuously without animation in Android

I want to know how to move a view from top to bottom continuously without animation. I am asking this because I want to get the position of the view at every step so that I can check that if there is any collision between that view and any other view.
With animation you can move (not exactly move) a view from one position to another position (Animator class), but animation produces an illusion to the user that it is moving but it's position is fixed all the time. So this can't be done using animation?
Second approach is incrementing position of view. I applied this method in onCreate(). If I used it without Thread.sleep(50) then the activity doesn't show the view, if I applied it with Thread.sleep(50) then activity doesn't start for some period.
Property animation (subclasses of Animator class) actually move the view, as they update the actual property of the view. It is the view animations (subclasses of Animation class) that don't move the actual view and instead just where it appears to the user.
Source:http://developer.android.com/guide/topics/graphics/prop-animation.html
Quote: With the property animation system, these constraints are completely removed, and you can animate any property of any object (Views and non-Views) and the object itself is actually modified.
You also shouldn't start moving things around in the onCreate method as things are still initializing (onwindowfocuschanged is recommened). Also if you call thread.sleep, you are going the sleep the main UI thread, hence freezing the application for a time.
Solved the problem using ValueAnimator :-
CodeSnippet :-
va=ValueAnimator.ofFloat(0.0f,size.y);
va.setDuration(5000);
va.setRepeatCount(va.INFINITE);
va.setRepeatMode(va.REVERSE);
va.start();
va.addUpdateListener(new AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
// TODO Auto-generated method stub
bullet[0].setTranslationY((Float) va.getAnimatedValue());
Rect R11=new Rect(bullet[0].getLeft(),bullet[0].getTop()+(int)bullet[0].getTranslationY(),bullet[0].getRight(),bullet[0].getBottom()+(int)bullet[0].getTranslationY());
Rect R21=new Rect(ball.getLeft(), ball.getTop(), ball.getRight(), ball.getBottom());
if(R11.intersect(R21))
va.cancel();
}
});

JavaFX Gridpane out of shape

I have a problem adding a gridpane to an AnchorPane in Scene Builder! The GridPane is completely out of shape as soon as I put it into the window. The actual window is at the position where it is supposed to be but the grid with the rows and columns is displaced. A screenshot shows what I mean:
Gridpane
Try updating scene builder to 2.0 or higher and re-add the GridPane or try changeing the layout settings from USE_COMPUTED_SIZE to constants. Or if it comes to it add the GridPane in java by doing:
#FXML
AnchorPane root;//This will be at the top of the page bellow where you define your class
GridPane gridPane = new GridPane();
root.getChildren().add(GridPane);//switch root out for the name of you anchor pane
I hope this helps.

Is it possible to wrap Group Panel in other kind of Panels in Scene Builder?

I'm wondering if is it possible to wrap in my main Group Panel in other kind of panels ?. Actually i can do it with code but i want to deal with it only from Scene Builder to arrange components more easily. For example you can see a simple code section of how i manage to wrap my main Group Panel in Boder Pane.
// My main panel which initialized automatically to Group Panel
rootPane = FXMLLoader.load(getClass().getResource("Risk3.fxml"));
FlowPane flowPane = new FlowPane();
//Text Box 1
TextArea countryInfoText = new TextArea();
countryInfoText.setPrefWidth(100.0);
countryInfoText.maxWidth(100.0);
flowPane.getChildren().add(countryInfoText);
flowPane.setPrefWidth(countryInfoText.getPrefWidth());
BorderPane borderPane = new BorderPane();
borderPane.setCenter(rootPane);
borderPane.setLeft(flowPane);
scene = new Scene(borderPane);
primaryStage.setScene(scene);
primaryStage.show();
but Scene Builder doesnt let me wrap this root (or Group Panel in other words) in other Panels. You can see the snapshot below as an example.
Hope i had been clear to you and i will appreciate a lot for every response. So thanks anyway.
ok guys i made it. The trick is you have to wrap the panel with changing the source code of fxml file. So i included the line
<BorderPane id="BorderPaneDocument" fx:id="mainPanel" xmlns:fx="http://javafx.com/fxml" fx:controller="javafxapplication1.RiskControllerClass">
<center>
<Group>
.
.
</Group>
</center>
</BorderPane>
which Group was the main panel i wanted to wrap in BorderPane. So i created a Border Panel in fxml file and put the group panel on center of Border Pane. It works perfectly with this way and also i can modify every part from Scene Builder.

Child window with maximize and close buttons

Still working on learning here ... I'm trying to make an application window (stage) into which I can call child windows. The parent naturally comes with minimize, maximize and close (x) buttons, but when I add a child window I can't move or resize the child, and it does not have the standard three buttons.
Here's code I've been toying with:
// Stage ventasStage = new Stage(); // originally the child was stand alone and had the standard 3 buttons
AnchorPane ventas = (AnchorPane) FXMLLoader.load(Punto_de_Venta.class.getResource("VentasGUI.fxml"));
// Scene ventasScene = new Scene(ventas); //"stage" and "scene" removed to add "getChildren"
home.getChildren().add(ventas);
The getChildren gets my new window to be part of the parent scene, but I cannot get the 3 standard buttons. I assume the buttons are added to a Stage and NOT to an AnchorPane (which is what getChildren is getting here) but getChildren can't be used with a Stage, right? So how do I make a parent with interchangeable children where each child is moveable, resizable and has the standard three buttons (minimize, maximize and close)?
Three buttons correspond to a standart Window (it is provided by OS), and it is Stage. Scene - is an object, which corresponds to scene graph and is a propeerty of stage. So use stage.setScene(..) to set Scene to Stage. Stene has a root node (usually, some kind of layout). And it seems for me, that you should use Scene.setRoot(...) method.
BTW, about Stage: you can use stage.init...() to use different decoration schemas, and different types of modality.

How can I remove only the 'minimise' button from stage components and how can I customize the components in JavaFX?

How can I remove only the 'minimise' button from stage components and how can I customize them in JavaFX?
I am using Netbeans 7.1.2 and created a simple JavaFX app. I have the object of stage named primaryStage. How can I achieve it?
Unfortunately JavaFX 2.2 doesn't yet provide API to manipulate system window buttons.
Although you can achieve that by removing system controls with
primaryStage.initStyle(StageStyle.UNDECORATED)
and providing your own ones to maximize, close, etc.
You can find an example in standard sample named Ensemble which follows described approach:
http://www.oracle.com/technetwork/java/javafx/samples/index.html
You can do it like this
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml"));
Parent root = (Parent) loader.load();
primaryStage.setResizable(false);
primaryStage.initStyle(StageStyle.DECORATED);
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
The key is setResizable(false)

Resources