Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Complex Java-Fx issues (rendering the different fxml documents in the same window)

    I try to render another Java-Fx view (fxml document) in the same Window (stage) using button.
    Indeed I got the exception: No controller found.
    Here is the part of fxml document: FlowPane-Hbox-Button nesting
    (I did not used Anchorpane as after creating it in SceneBuilder it did not rendered my nested controls in Ecllipse).
    <HBox prefHeight="54.0" prefWidth="456.0">
    <children>
    <Label prefHeight="42.0" prefWidth="195.0" text="Please sign in" />
    <Button mnemonicParsing="false" prefHeight="46.0" prefWidth="141.0" text="SignIn" onAction="#RegisterAction" />
    </children>
    </HBox>

    Here i code for java-fx main class:
    Java FX Code:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.Parent;
    import javafx.fxml.*;
    import javafx.event.ActionEvent;
    import java.io.IOException;
    
    public class Main extends Application {
    	
    	//Parent root; //Is it normal to put Stage out of start() method
            //Anyway it is diifficult to not use stage from outside start()
           //method but how to put new fxml in start()?
    	Stage primaryStage;
    	
    	@Override
    	public void start(Stage primaryStage) {
    		try {
    			Parent root=FXMLLoader.load(getClass().getResource("Log.fxml"));
    			Scene scene = new Scene(root);
    			primaryStage.setScene(scene);
    			primaryStage.show();
    			primaryStage.setTitle("Test");
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    	}
    	
    	@FXML protected void RegisterAction(ActionEvent event) throws IOException {
    		Parent root=FXMLLoader.load(getClass().getResource("Signin.fxml"));
    		Scene scene = new Scene(root);
    		primaryStage.setScene(scene);
    		primaryStage.show();
    		primaryStage.setTitle("Test2");
        }
    	public static void main(String[] args) {
    		launch(args);
    	}
    }
    What is incorrect in my approach and code as I want use extensively
    the different views (redisplay) in the same window.
    Moreover it should be constant size, and probably should display some list (catalogue) of items -
    if it possible and appropriate in Java-fx. I aslo should note that SceneBuilder 2.0 doesnt allow freely to compose the scene (fxml panes and controls) as it partially got invisible and it is difficult
    to settle it.
    Last edited by ark; 12-02-2017 at 04:41 AM.

  2. #2
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    Here I used such code to make simple moving forward and back with 2-3 simple scenes in the same window (frames). I just added 2 references for fx:controller in fxml docs.
    I used FlowPane layout - but I am interested should it be enough to make complex app with about 10-15 scenes inside
    normal flow.
    Java FX Code:
    import java.net.URL;
    import java.util.ResourceBundle;
    import javafx.application.Application;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.Parent;
    import javafx.scene.layout.FlowPane;
    import javafx.fxml.*;
    import javafx.event.ActionEvent;
    import java.io.IOException;
    
    public class FirstController implements Initializable {
    	
    	@FXML private FlowPane rpane;
    	
    	public void initialize(URL location, ResourceBundle rb) {
    	}
    	
    	@FXML protected void RegisterAction(ActionEvent event) throws IOException {
    		Parent pane=FXMLLoader.load(getClass().getResource("Signin.fxml"));
    		rpane.getChildren().setAll(pane);		
        }
    	
    	@FXML protected void LogAction(ActionEvent event) throws IOException {
    		Parent pane=FXMLLoader.load(getClass().getResource("Log.fxml"));
    		rpane.getChildren().setAll(pane);		
        }	
    }

  3. #3
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    So could I reference forward rpane as fx:root even if I would like to make some flowpane with dynamically (runtime) created content? Could I change at runtime the stage size?
    Then - Should I use property binding like that JavaFX Tutorial - JavaFX Binding
    to bind FXML properties to Object properties. For example should it is obligatory to use SimpleStringProperty to link textfield to String field in Object. How I can bind Object property to fxml field unidirectionally.
    I also wonder taking account from code
    Java FX Code:
    firstNameProperty().get() and firstNameProperty().get()
    where is get() and set() methods defined for StringProperty?
    I also need password field -- that seems to be absent in jdk 1.7 but present in jdk 1.8 -- in what SceneBuilder version it is present as in 2.2 seems to be abnsent despite Datepicker control is present.
    Last edited by ark; 12-03-2017 at 02:52 AM.

  4. #4
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    381
    Rep Power
    4

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    I am not sure what the idea is here. Do you want to use multiple fxml files in one Stage? Each fxml file will have its separate controller then.

  5. #5
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    381
    Rep Power
    4

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    In case I am right and you want to work with multiple fxml files in one stage: I have dug up some notes of mine:

    Multiple fxml files in fxml layout:
    * Create an fxml file for each file you want to include.
    * create a controller class for each file you want to include. Leave empty for now
    * select anchor pane, choose file->include-> fxml. choose file that you have created earlier. (Happens in Scenebuilder). File will show up root element. Click and drag onto graphic element where you want it.
    * hook up controller class with fully qualified name, just as main fxml class
    * give the main fxml anchorpane an fx:id
    * children fxml file: give main graphic element a fx:id (“yadayada”) and save
    * in the fxml main file: there should be a section that has fx: include content by now. add fx:id=“yadayada” with the fx:id you have given the children fxml main graphic element. caution: naming convention: the fx:id has to be same name as the source, just starts with lower case.
    * in the main controller create an instance for all children controller classes. If private, add annotation @FXML
    * in each children controller class, inject dependency by passing instance of main controller class. use setup as quasi constructor
    * you can also address sub-fxml-classes from ”outside” by passing dependencies there. if you call methods from outside always surround methods with
    * Platform.runLater(new Runnable() {@Override
    public void run() {boardTabController.updateGraphics(); // as example}
    Last edited by benji2505; 12-03-2017 at 03:44 PM.

  6. #6
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    Indeed aforementioned example works.
    I load title page with option to Log, or click to Sign In.
    When click Sign In I got to Sign In fxml to fill data.
    when clicking Signin I load again Title(Log).fxml (It is just for testing).
    Indeed when I create in Signinbutton handler method - LogAction(ActionEvent event) -
    the object of special Account class - that is filled by Signin textfields during instantiation -
    and want to pass this object.toString() for some label in Log,fxml - I got nullPointer exception (IncorrectInvocation exception) - that means that account==null? Moreover when checking this I just want to fill
    label1.setText("testingcheck") (label present in Maincontroller) - I cannot see this label when returning from form2 (by button2) to form1 (could be form3). Why I cannot pass from form2 the object created from its fields, and called by its button2 to form1 (or form3). It is very important as I need to pass such object in json to remote server.
    Indeed form1(button1)->form2(button2)->form1(button1) transitions works correctly. Why object is lost or not created and label not displayed.
    I created 2-3 fxml document for every forms indeed just with one maincontroller -- but it should not be the reason of nullpointer exception for such simple beginning.

  7. #7
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    381
    Rep Power
    4

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    Could you post the stacktrace and the code that is referenced in the stacktrace?

  8. #8
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    I have solved the issue with object transfer beetween 2 windows (scenes or panes) in rather simple way.
    Indeed I used the same controller -- the second would be helped in nothing except I just used 2 controllers with 2 methods, but why not 2 instances of controller - moreover I did not needed directly create it.
    The solution (hinted after several dozen pages of s.o.f. forums) was in creating instance of FXMLLoader fxmloader =new FXMLLoader (...);
    Java FX Code:
    	FXMLLoader loader=new FXMLLoader(getClass().getResource("Log.fxml"));
    		loader.load();
    		FirstController fc2=loader.getController();
    		Parent pane=loader.getRoot();	
    		label1.setText(accountobject.toString());
                    rpane.getChildren().setAll(pane);
    Last edited by ark; 12-05-2017 at 02:45 AM.

  9. #9
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    As it is not possible to get headers, status codes with Resttemplate::getForObject method, could I apply GetforEntity(Postforentity) to the restservices that returns no ResponceEntity (with headers, status codes), but just object or list of objects.s
    As I have seen that even Spring configuration is applied to java-fx main class (such as @springbootapplication or built-in Applicationcontext object), should it means that this application is used with nested web-content or it is used for better communication of desktop java-fx apps with spring servers?
    In my java-fx desktop application I want to create the Admin cabinet that would get the message box (it should be some kind of label, that shows the new messages, with ability to click on it). What should I use: label, button?

  10. #10
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    Here is such moment that when I use json-serializing on enum by
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Seazon { --- f.e. --
    I got in the array (not all enums should be) of JSON object of such kind as
    [{
    "name": "Winter"
    "ordinal":1}
    , {
    "name": "Spring"
    "ordinal":2}
    As I have seen on example How To Serialize Enums as JSON Objects with Jackson | Baeldung it should be more plain, probably without
    "name", or at least "ordinal".
    Besides, I just interested that the Json-to-Object conversion would be the same -- that is no permutaion or exception would happens for such field of my class as List<Enumname>?

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    I'm not sure what you are trying?
    How exactly do you want your enum to be represented in JSON?

    For your other question about getForObject, I'm not sure what you are asking for.
    There seems to be a lot of different, unrelated, questions.
    The one I can easily answer is, if you need the object and the headers then yes, you use get/postForEntity.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    You have seen that Jackson returns such kind of list of enums in Json (suppose you want to choose just 2 of 4 seazons).
    Indeed the "google.gson" library provide more consize list of enums in json - "users" ["WINTER","SPRING"] - so if choose 2 methods for serializing and deserializing there could happens the exception or non-valid convertion.

  13. #13
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    The relating to responseentity -- here is example-- Spring MVC 4 RESTFul Web Services CRUD Example+RestTemplate - WebSystique
    There is service returns the responceentity where statuscodes are atttached manually - so
    resttemplate could use getforobject.
    Indeed I want to use getforobject or getforentity for the service that returns just object or list of objects --(for example Account object and list of accounts). I do not create that service so
    I cannot change and adapt for my resttemplate.
    So could I use getforobject and getforentity for such service over network? Whether I should use just exchange() method of Resttemplate?
    Then there is such issue - more overt (in previous example there is different methods for requests).
    That service has JPA Dao layer with entity classes
    for example
    @Entity
    class Account {

    @ID@GenerateValue
    int iD;
    @column(name="name")
    String name;

    Indeed on client side
    I created
    such class
    as
    public class Account {
    //int iD; --is generated on server by JPA
    String name;

    How should I adapt my client class to JPA-annotated
    server class to make identical transfer by network with the help of json format.
    I probably cannot use ID field
    as it is not known when I send data from java-fx form,
    so what about other annotaions @entity, @column, @table in my input Account class?

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    For the JSON, if you just want the value ("WINTER", "SPRING") then don't use the JsonFormat annotation, where you are telling it to treat the enum as an object, so that is what it does.
    That's what the link you provided says.
    They only use the annotation because they want the enum to be treated as an object.

    For the RestTemplate question, if you need the status etc then you should be calling get/postForEntity.

    There's nothing else I can say about that.

    When consuming a REST service, you should not care what goes on behind the scenes. You should be building objects that match the REST interface, not the behind-the-scenes entities.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  15. #15
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    What about using Spring JPA annotations (JPAControllers instead of Hibernate sessions) -- should its annotations @entity @column serialized by json, or they are just designated for one-time using -- just to map entity to table (row with column separations), and after retrieving from db(table) they are free of it.
    If my server entity class has some format -
    Java FX Code:
     @Entity
    class Account {
    
    @ID@GenerateValue
    int ID;
    @column(name="name")
    String name;
    What format should be my form-mapping class that take form values to create object (of class) that is send by post request to server to be saved to db?
    Could it be free of annotations -- just
    Java FX Code:
    public class Account {
    //int iD; --is generated on server by JPA
    String name;
    It seems to be that ID should be absent in client class definition, or otherwise just to be 0, before generation on server?

  16. #16
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    And what about controlling which actor(entity) send request - should I use setcookies in java-fx client login request, that would return cookies to client desktop pc (after succesful login), and would manages father requests to server db in current session?

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    This question seems to be going all over the place.

    What is it you are trying to do?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    Maybe I ask another more relevant question -- the spring boot server use spring security authentication-for client requests. But it should create automatically login and logout forms. But this forms should be on client in java-fx app. How this issue could be resolved?
    Last edited by ark; 12-14-2017 at 01:55 AM.

  19. #19
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    Here I have very important as for me question. I have tried to launch spring boot server that my colegua created for project.
    Indeed as my eclipse has set to update dependencies - about 300-400 mb was downloaded but in vain -it needs more space on disk C to download futher and server project is marked red. Indeed there are several dependecies and plugins no more 1mb each. Why it downloads more and more?
    Should it try to download the repositories of maven --
    <repositories>
    <repository>
    <id>spring-milestones</id>
    <name>Spring Milestones</name>
    <url>https://repo.spring.io/milestone</url>
    <snapshots>
    <enabled>false</enabled>
    </snapshots>
    </repository>
    </repositories>
    <repository>
    <id>spring-snapshots</id>
    <name>Spring Snapshots</name>
    <url>https://repo.spring.io/snapshot</url>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </repository>
    <pluginRepositories>
    <pluginRepository>
    <id>spring-snapshots</id>
    <name>Spring Snapshots</name>
    <url>https://repo.spring.io/4snapshot</url>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </pluginRepository>
    <pluginRepository>
    <id>spring-milestones</id>
    <name>Spring Milestones</name>
    <url>https://repo.spring.io/milestone</url>
    <snapshots>
    <enabled>false</enabled>
    </snapshots>
    </pluginRepository>
    </pluginRepositories>
    How to avoid its downloading if so - or how to limit the dependecies download, just nessesary?

  20. #20
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Complex Java-Fx issues (rendering the different fxml documents in the same window

    Relating to previous updating of maven project startup in ecllipse (never used maven in practice)- just unchecked all updates, download artifact sources before new project import, indeed there is issues with creation of mysql db with jpa annotation in update mode.
    So here is first exception during spring boot project launching - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Unknown database 'market' ...
    Last edited by ark; 12-15-2017 at 02:36 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Java FXML, JavaFX, Swing?
    By ctullar in forum JavaFX
    Replies: 5
    Last Post: 07-27-2015, 05:57 PM
  2. How complex is too complex for a single class?
    By manji51 in forum AWT / Swing
    Replies: 7
    Last Post: 07-08-2011, 08:20 PM
  3. Programming Issues, JForm second window wont open.
    By DarkJ3JB in forum New To Java
    Replies: 1
    Last Post: 04-16-2010, 02:23 PM
  4. manual BMP rendering colour issues
    By Goseph in forum AWT / Swing
    Replies: 0
    Last Post: 02-24-2009, 09:26 PM
  5. Parent & Child window issues......
    By jithan in forum New To Java
    Replies: 2
    Last Post: 09-20-2008, 10:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •