Scenebuilder not showing controller fields - java

There's a weird behaving I'm noticing in SceneBuilder, I successfully attach the scene to the wanted Controller as shown here :
but sometimes it can't detect the fields annotated with #FXML annotation
public class MainViewController
{
EntityManager em;
#FXML
public Parent View;
#FXML
public BorderPane ContentArea;
public MainViewController()
{
}
...
Scenebuilder should give suggestions by showing the available #FXML annotated fields from the controller, sometimes it s working correctly , but sometimes it doesn't, until I close Eclipse reopen it, but don't understand the problem, and it s really handicapping me, is there any explanations ?

I have faced this problem from the other direction. When making changes in Scenebuilder and starting the Java application the changes are not in the GUI. I always have to make a clean first.
I think you are facing a similar problem, so try to clean your workspace. Maybe you have to restart Scenebuilder also.

Related

ZK 8.5.0 how to override button widget setLabel function

The ZK setLabel() function of Button widget does not work; when the code runs to the line like foobutton.setLabel(mystring), the button disappears from the browser.
In the eclipse IDE, if I hover on the setLabel() function, the IDE shows this message:
If label is changed, the whole component is invalidate.Thus, you want to smart-update, you have to override this method.
Using ZK 8.5.0
Inside the controller class, I declare:
#Wire
Button delSelectedMonitor;
Inside the controller, I implement a class which implements EventListener:
public class onClickHolderEditMode implements EventListener{
public void onEvent(Event event) throws Exception {
clickedDivEditMode = (Div) event.getTarget();
clickedDivIdEditMode = clickedDivEditMode.getId().split(myUtil.monitorholderString)[1];
String curName = getCamNameById(clickedDivIdEditMode);
delSelectedMonitor.setLabel("DELETE:"+clickedDivIdEditMode+","+curName);
}
}
event binding:
tmpdiv.addEventListener("onClick", new onClickHolderEditMode());
My expectation is that when someone clicks the tmpdiv, the button delSelectedMonitor will change its label according to the property of tmpdiv. However as I say previously, the button is just disappearing.
https://www.zkoss.org/wiki/ZK_Client-side_Reference/General_Control/Widget_Customization
I have tried the section "Specify Your Own Widget Class" at the above website link, but the browser will be pending.
Please help, thank you.
I would prefer a different approach.
Why not use a
<button label="#load(vm.xyz)" ... />
(I wrote using MVVM pattern) and modify variable xyz in clicking action?
Check out http://books.zkoss.org/zk-mvvm-book/8.0/syntax/load.html for implementing guide.

Loading different FXML files from a controller

I apologize as I understand that the question is a bit broad in nature. What I want to achieve is having the ability to load different FXML files (located in different packages) when specific conditions are met, for example when a button is pressed or when a certain condition is satisfied. So far I've managed to load a file when a button is pressed.
#FXML
private AnchorPane rootPane;
#FXML
private Button btn;
#FXML
private void loadLoginWindow(javafx.event.ActionEvent event) throws IOException {
AnchorPane pane = FXMLLoader.load(getClass().getResource("login/MainWindow.fxml"));
rootPane.getChildren().setAll(pane);
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
And it works fine but for one button and one handler only, as soon as another is added it stops working, it seems that only one can work at the time. So clearly I'm missing a bunch of important info but every tutorial I've had a look at doesn't address this point because they don't even get there (They all revolve around a single file, or they rely on hiding and showing panes from the same file)
Does anyone have any good tutorial or comprehensive guide to do this kind of things?
Thanks in advance.
What can happen is the link to the controller within the FXML file can be incorrect. Even though the file location may not exist, the application will still build.
<AnchorPane id="AnchorPane" fx:controller="main.MainController">
The pathway in the fx:controller need to be correct.
Cheers!

Mutiple FXMLs with multiple controllers in one Main FXML

Recently I started learning JavaFX and now something is bothering me and I can’t find a solution to my “problem”. I have found similar questions and couple of solutions to problems like mine, but I couldn’t find one that’s working for me or simply I am doing something wrong. What I want to do is to have one main FXML file with its own FXML Controller Class. Then I want to add (import) other FXML files, which also have controllers, in the main FXML. I tried couple of things, but nothing worked, so I decided to describe what I am doing. First I am creating the Main FXML file with Scene Builder and then I am creating the Controller for the Main FXML. Then I am setting in Scene Builder the controller class for the Main FXML to be the Main Controller (of course…). After that I am doing the same for the second FXML. Then I am trying to import the second FXML to the Main FXML and it works fine, if I haven’t set a controller for the second FXML. If I have however selected a controller for the second FXML before importing it to the Main FXML, I am still able to import the FXML file and save it, but after I try to run the program, I am getting an error. So basically what I am trying to do is to have multiple FXML files with their own controllers in one Main FXML file, which also has a Controller Class. I am not exactly sure that this is possible at all, so please tell me is that possible at all, and if it’s possible, what am I doing wrong. This is my code :
public class MainSceneController implements Initializable {
#FXML
private TextField mainTxtField;
public MainSceneController() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MainScene.fxml"));
fxmlLoader.setController(this);
fxmlLoader.setRoot(this);
try {
fxmlLoader.load();
} catch (IOException exc) {
} }
#FXML
public void buttonActionMethod(ActionEvent event) {
mainTxtField.setText("Button1 is clicked");
}
#Override
public void initialize(URL location, ResourceBundle resources) {
} }
I called the second FXML and the second controller LeftScene and LeftSceneController, so here is the code for the second controller :
public class LeftSceneController implements Initializable {
#FXML
private TextField leftTxtField;
public LeftSceneController() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MainScene.fxml"));
fxmlLoader.setController(this);
fxmlLoader.setRoot(this);
try {
fxmlLoader.load();
} catch (IOException exc) {
}
}
#FXML
public void button2Action(ActionEvent event) {
leftTxtField.setText("Button 2 is clicked");
}
#Override
public void initialize(URL location, ResourceBundle resources) {
} }
And finally, this is the MainClass, in which are the main method and the start method :
public class MainClass extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("MainScene.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Multiple FXMLs in one");
primaryStage.show();
} }
I hope you are getting what I want to do. As I said, I have tried a lot of things and none of them worked how I wanted it to. This version is compiling and it’s running, if I don’t set a controller class for the second FXML before importing it, but as you can expect, the second button from the imported FXML is not doing anything. I would post screenshots, if I could, but I am new here and usually I am only reading, so I am not allowed to post screenshots. Also I tried to post my FXML code, but I was having problems with the system and I couldn't post more than one line of the code.
So… Is it possible to make this work how I want it to or not?
And also if you read all this mess, thanks at least for your time! :)
It has been a while, but finally I found an answer to my question. I found this video on YouTube and it is showing exactly what I needed. Although I found a couple of problems while I was doing the things from the video step by step.
First of all, if I import another FXML file into the main FXML, like in this tutorial, SceneBuilder is importing the FXML like the things from the imported FXML are in the main FXML and this causes problems. What I mean is for example if you have a Button in the imported FXML, when you import it in the main FXML with SceneBuilder, the imported Button appears in the main FXML like a new Button with all the information for it (postion, onClickMethod, etc.) and that it's not how it's supposed to be. This causes errors, because Java is looking for the onClickMethod for the imported button in the Main Controller and not in the Controller of the imported FXML. I don't know why it's different by me and it is not like in the video, but the solution is simple. If you want to import a FXML file into another FXML, you should do it with an editor and you just have to add the following line in the content of the main FXML :
<fx:include fx:id="importedFXML" source="ImportedFXML.fxml" />
The important thing in this case is that the fx:id should be with the same name as the .FXML file, but with a small first letter.
And the other thing, which was shown in the video and which caused problems by me was if you want to have a multiple imported FXML files and you want them to communicate with each other. The video is showing how to do that, but it is not mentioning that the Controller objects of the imported FXML files, which you have to create in the MainController, must have the same names like the fx:id + the word Controller. For example with the fx:id from above, the object should look like this :
#FXML private ImportedFXMLController importedFXMLController
if the ImportedFXMLController is the controller of the importedFXML
So, I hope that this is going to be helpful to someone.

JavaFX getting scene from a controller

I recently started playing around with Java FX, FXML, and scene builder, and I've been trying to add key listeners to one of the controllers for a scene. When I do this though, the key listeners don't work as they should, and I figure it's because they're not focused onto that particular scene. I tried to get access to the scene the controller was part of in order to set it directly, but it comes up that it's part of a null scene.
Is there a way to gain access to the scene that this controller is used in in order to try and assign key event and listeners to that particular scene? Should I go through the rootController which is static throughout the whole application? Or, better yet, is there a simpler way of going about this?
Most examples I see assume that everything is mostly together in a main class or separated amongst a couple of other classes without FXML being brought in, and I'm not sure how to apply their fixes when I have the java controllers, FXML pages, and the main application all separated.
Thanks for any help!
Use any of the controls that is bound in the Controller and use getScene() on it.
Remember not to use it in initialize() as the root element(though completely processed) is still not placed on the scene when initialize() is called for the controller
public class WindowMainController implements Initializable {
#FXML
private Button button;
#FXML
private void handleButtonAction(ActionEvent event) {
System.out.println(button.getScene()); // Gives you the Scene
}
#Override
public void initialize(URL url, ResourceBundle rb) {
System.out.println(button.getScene()); // Prints null
}
}

Minimize intro part in eclipse application

I have created my own intro in eclipse application as follows:
public class CustomIntro extends IntroPart {
public void createPartControl(Composite container) {
//add intro, works perfectly fine
}
//override other essential methods
}
The above code works perfectly fine, now I want to minimize this intro programatically. Upon a click of button the intro should be minimized. Actually I want to launch a internal browser upon click of button, and the intro should be minimized and launched internal browser should be visible.
As suggested by #greg-449, I extended the IntroPart than implementing IIntropart. Thanks for that, but my issue still remains. Any help is appreciated.
As #greg-449 pointed, you should extends IntroPart abstract class as is explained in the documentation.
You can use setPartState().
Use this in your IntroPart:
this.getIntroSite().getPage().setPartState(this.getIntroSite().getPage().getActivePartReference(), IWorkbenchPage.STATE_MINIMIZED);

Categories