Javafx: write code only for a part of a fxml interface - javafx

I know my title is a little too generic, but I sincerely have no idea how to ask it. So, the topic is JavaFX. I have a part of the interface coming from a fxml file and another part that I'd like to code manually. So my question is, more specifically, is there a way to insert a sort of pane into another, coming from scene builder? If you have "questions about my question", please, ask me!

Ok, I managed to dynamically add a label on button click, thanks to your suggestions.
Anyway, i tried to add imageviews, but i get a lot of error! This is my code:
ImageView pages[] = new ImageView[8];
for (int i=0; i<8; i++) {
pages[i] = new ImageView(new Image(FlowLayout.class.getResourceAsStream("src/provaProgetto/Penguins.jpg")));
base.getChildren().add(pages[i]);
}
What's wrong?

Related

Javafx working with the same window problem

What I am trying to do:
I have menu and and after click I am trying to remove unnecessary TextFields.
What I did:
I used this example:
"In JavaFX, nodes can simply be removed from a Parent (e.g. an AnchorPane) using .getChildren() following by .remove(Object o)
AnchorPane ap;
ap.getChildren().remove(btn);
I tried to use:
FXMLLoader load=new FXMLLoader(getClass().getResource("LoginRegister.fxml"));
Parent root = load.load();
root.getChildren();
But my root does not have getChildren() function.
Where could be the problem?
Thank you in advance.
EDIT: FOUND THE ANSWER HERE: How to access UI components from SceneBuilder in JavaFX
WHAT I DID WRONG: I USED IN FXML FILE AND IN CONTROLLER DIFFERENT FX:ID's

Issue creating button in which opens a window/stage

Im having issues with understanding what should be the model in my ViewLoader statement while making a JavaFXML MVC project
I have a button on the main menu in which when the user clicks it will take me to another window called known as the build menu.
Ive tried a multitude of possible models that I think would work including getBuild etc.
https://imgur.com/Ubz43CI
Here is a screenshot of my Controller and View file
https://imgur.com/0C3FUG3
Here is a screenshot of my Model file
The expected result based off a similar project ive found online is that when the button is clicked a new window pops up. Im assuming the reason this doesnt work is because the getBuild method/statement needs to be initialised in the Controller class however I am unsure as of how to do that as getBuild is a method in my Model class
If you are only Navigating from one scene (window) to another the code is as listed below. Why do you think you need to have a MVC pattern to do this is is confusing.
Here is the code to go from one scene to another we name all our Anchor Pane's somenamePane so we know where we are and where we are going.
public void goTO() throws IOException, SQLException{
stage = (Stage)paneStart.getScene().getWindow();// pane you are ON
ckbookPane = FXMLLoader.load(getClass().getResource("manager.fxml"));// pane you are GOING TO
Scene scene = new Scene(ckbookPane);// pane you are GOING TO
scene.getStylesheets().add(getClass().getResource("checkbook.css").toExternalForm());
stage.setScene(scene);
stage.setTitle("Check Book Manager");
stage.show();
stage.sizeToScene();
stage.centerOnScreen();
}

'Reusing' Controllers in JavaFX

First off, I am new to the world of JavaFX, so I might lack some basic knowledge, sorry about that. Also, this is the first time I ask a question, so I don't know how to formulate it.
What I want to do is quite basic: I have multiple pages which the user can switch between by pressing next/back. What is the best way to code this so the changes made by the user will be there when he returns to a page? I not only want the TextFields to have the same contents but also the attributes. Note: Every page has its own Controller which implements a common Interface.
I have already tried setting the pages via a loader and using the loader.setController() method and handing over the Controller Object I got from loader.getController() when first creating it, but that doesn't seem to have any effect.
Sorry if this is already answered somewhere, I couldn't find it.
Thanks in advance to anyone who takes his time to help me!
EDIT:
The code with which I change the pages in the ControllerHolder Class
ResourceBundle bundle = FXMLUtil.getResourceBundle();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource(
FXMLUtil.getFXMLPageByIndex(pageNumber)
));
loader.setResources(bundle);
initWizardHolder.getChildren().setAll(
(Node) loader.load());
currentController = loader.getController();

qt layout()->setSizeConstraint

I have a problem with the layout () in Qt 5.
I want to make a dynamic variable dialog.
![enter image description here][1]
Below is the code for the constructor:
SortDialog :: SortDialog (QWidget * parent)
     : QDialog (parent)
{
     setupUi (this);
     SecondaryGroupBox-> hide ();
     TertiaryGroupBox-> hide ();
     layout () -> setSizeConstraint (QLayout :: SetFixedSize);
     setColumnRange ('A', 'Z');
}
The project is built successfully, but when you start receiving a signal from the operating system.
Signal: SIGSEGV
Purpose: Segmentation fault
If you delete a row
layout () -> setSizeConstraint (QLayout :: SetFixedSize);
The program works.
Please, help me.
P.s.:This is an example from the book c++ GUI Programmming with Qt 4 (page 31)
I was having the same problem.
I just solved it.
Probably you don't want the answer after two years, but I really want to write about this somewhere, because there is nothing about this little issue on the web.
The problem was that Qt Designer didn't generate code to set dialog's layout.
I just opened ui_sortdialog.h and found that out of SortDialog a widget was created. Than with this widget a layout would be created. The layout is called gridLayout_4, and every widget and layout of the form are added to this one. When I added to function retranslateUi line SortDialog->setLayout(gridLayout_4); everything worked. Generated code created layout and did everything what needed to be done, but it left SortDialog without any reference to the layout, therefore layout() returned zero.
That's because you didn't create a layout.
Go back to designer and click the form and choose lay out in grid.
If you don't do this, the layout would be 0 and the program will crash.
You have to create a layout, like QVBoxLayout.
QVBoxLayout *layout = new QVBoxLayout;
layout->setSizeConstraint (QLayout :: SetFixedSize);
setLayout(layout);
I fixed this with changing in Designer Form. Make sure that the layout in the Qt Designer is good. Especially "Form -> Adjust Size" at the end. (in the book page 33; creating a "Form-> Lay Out in a Grid"). Use the original code from the book.

MvvmCross UINavigationController customise navigationBar

Further to my experiences with MvvmCross, I've managed to build an app for iPhone which starts with a TabBarController. I can also successfully navigate within each tab to deeper levels. The problems start when I want to customise the navigationBar on the deeper levels - setting the backButton colours, etc. The code I use for navigation is the standard viewModel code -
this.RequestNavigate<InJourneyViewModel>();
…which works fine, but I can't do anything to the navigated-to view's navBar, other than set its title.
Any thoughts or advice appreciated!
I think it might help if you posted some more of your code that is failing.
My suspicion is that the problem is a more generic Cocoa, MonoTouch and/or backbarbutton problem.
I've just played with the ViewDidLoad code in MapView.cs in https://github.com/slodge/MvvmCross/tree/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch
At the end of this, I was able to add some bar button changes like:
var leftButton = new UIBarButtonItem("FooBar", UIBarButtonItemStyle.Bordered, null);
leftButton.TintColor = UIColor.Green;
NavigationItem.SetLeftBarButtonItem(leftButton, false);
NavigationItem.RightBarButtonItem.TintColor = UIColor.Red;
Which resulted in:
Alternatively, by placing code in the WelcomeView:
var leftButton = new UIBarButtonItem("FooBar", UIBarButtonItemStyle.Bordered, null);
leftButton.TintColor = UIColor.Green;
NavigationItem.BackBarButton = leftButton;
Then I succeed in achieving:
Alternatively, by using code like:
UIBarButtonItem.AppearanceWhenContainedIn(typeof(UINavigationBar)).TintColor = UIColor.Blue;
Then this enabled me to customise all the navigation bar buttons like:
At one point, I also managed to achieve:
... but sadly I've genuinely no idea which code combo gave me that! If your problem is with back buttons in particular, then I think you will need to dig around other questions and/or post some code and hope someone can help - there's lots of posts about how to do this, but I can't quite figure out what they all mean for MonoTouch - e.g. Separate title in NavigationBar and navigation buttons

Resources