Here is the problem,
I have a JavaFX application, main display element is a BorderPane.
I use the top of the BorderPane to display buttons, that will act like "navigation" buttons, and the center to display the current chosen application part.
Some solution, described on this link should do the trick :
https://community.oracle.com/thread/2598756
I'm really confused about the code, The only thing I really understand here is that it sets up some kind of changeListener on a list, supposed to hold the "selectedView".
Once the list changes, it triggers a function in the main part of the application, and this fuction SHOULD set the center element display with a new fxml file loaded.
So, I tried to implement quite the same example, only with 2 levels (main -> center) and get nothing working.
Here are the current files I created :
ScreenSwitcher.java
// Main class, loads the "main" fxml component
Main.fxml
// Main fxml component, BorderPane (buttons + center -empty-)
MainController.java
// Main controller, the magic should happen here
PaneOne.fxml & PaneTwo.fxml
// Children fxml, should only be displayed in the main->center element
PanelOneController.java & PaneTwoController.java
// Corresponding controllers
ViewControllerInterface.java
// An interface, as described in the given link explanation
https://github.com/Julo0sS/ScreenSwitcher
First, at app starting, I get this warning :
WARNING: Exception while evaluating select-binding [selectedView]
Then, when clicking on a button to switch the main display, nothing happens... I do have the console showing "CALL TO GOPANEWO" (or GOPANEONE), so it goes into the function code, but seems like the "changeListener" does not work...
Maybe I'm just wrong in the code, maybe there's a better/faster way to achieve what I'm trying, but actually, I'm just stuck on this...
Thanks for reading / help
Update One
Can get a part of the app working now,
The change currentView "event" is sent, and works correctly, WHEN sent by the child view itself (by click on a button in PaneOne, or PaneTwo), but does NOT work when triggered in the main view (in the top part of the borderpane, which is supposed to be a navbar)
Git repo updated with latest modifications...
Related
I'm working on polishing up an assignment. I am working with JavaFX and have 3 sequential scenes. The data from the first and second scenes is used in the third scene and consists of various types of inputs, all converted to String data to populate this third scene. Problem is, the only way I've been able to get it to work is to make an event handler, in this case a button. The appropriate data loads right up and everything is technically accurate, but I think having a button to press to load up the output data right after having pressed the button on the previous page to submit the data is kind of clunky.
Is there any way to make the elements I have set up to display the data automatically load the data in a non-clunky way? I thought about adding a mouse event to just watch for mouse movement, but that would potentially be kind of wonky if someone who doesn't fidget with their mouse were to run the program.
The only solution I've made actually work so far is to create a button and make the event for clicking the button load populate the data.
Thanks in advance!
I made a bit of a mess when coding my program however do not have time to fix it before submission. My program opens up to a 3D molecule viewer for Water, Methane and Methyl, this is done without FXML and simply creates panes, borders, canvas and cameras which you can manipulate to view 360 around the molecule. One button on my side bar switches into an FXML Gui for a chemistry database, in which I want to display my SQL data.
However, once the scene has been switched I cannot switch back. I have attempted to reference the main class in the original starting .java through the FXMLController however it simply says that Handler method is not assesable, I add the #FXML and again nothing fixes. So Instead I attempted to make a public method which calls the main from the same class, this would work other than the fact that it now says that the handler method is not found.
I have searched high and low and cannot seem to find an answer. I am very new to java and javafx and would love to see this project through to the end.(Especially because completing this one simple(or not so apparently) function will complete my project bar loading the SQL database inside the GUI.
I will post a link to the FXML code and the class in which the main class is found.
Thanks
https://gist.github.com/anonymous/753797aeca8f12c8086628b740525625 --> FXMLDocument
https://gist.github.com/anonymous/60c58df1268aa5adeafca8faabf14c4c --> Class that has main(String[] args)
So the generally Idea I have is having a basic JavaFX app. So I make a new project and it has the default stuff such as
#Override
public void start(Stage stage) throws Exception
{
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
and it has the basic button that when you click it prints hello world. So so far all i am trying to do is show you it is a basic default project.
now lets assume I have another class. Lets say that class runs on another thread and that when I type in a name into the console (in my case NetBeans) then it will update the button to say something else.
This is very general, I been googling and trying things with no perfect result. In hindsight, I am trying to make it so, I can have other classes edit the FXML document or elements on the page, then it will show on my program. I am not sure if I have to reload the FXML doc or reload the stage or what. I just wnat a guide or help on how to reference and change stuff around on a JavaFX FXML program. I been working on a chat program and been using normal Javafx with NO FXML and run into problems. So I am thinking about doing it on FXML. but I have times where I a class handle the user names and a class handle the messages for everyone to read and I need these classes to be able to edit the FXML document and reload it to show up. SO, if i user connects to the server, for example, the ListView object will now show that person name. like I said before, I have been able to do this working with Javafx without an FXML file, but my code is like spaghetti. Thanks in advance
I am going through a legacy application which is using Swing and i am struggling to figure out how the screens are changing when a user clicks a button. One of the reasons i cant figure this out is because this is the first time i am using Swing. I have read a book and got the basics but still struggling.
Basically, the screen i am looking at has a JSplitPane which has a number of shortcut buttons on the left and an empty pane on the right. When i click on the button, the right side pane is populated with a different screen depending on the button pressed.
Going through the code, i was expecting somewhere that there will be something that calls a setVisible() method depending on which button is pressed.
The actionPerformed method for each of the shortcut buttons looks something like this:
void shortCutBtn_actionPerformed(ActionEvent e) {
propertyChangeListeners.firePropertyChange("selectedShortCut", previousShortCutSel, currentShortCutSel);
mainPanel.updateUI();
}
I have gone through most of the code and came to a conclusion that the above code is what is causing the frame switching but i dont understand how that is happening.
Each screen is identified by a numeric constant. In the above code example, previousShortCutSel and previousShortCutSel refer to a numeric value that represents individual screens screen.
I have tried to look for documentation of how updateUI() works but i am lost. How does the above cause the content of the right panel of the JSplitPanel to be updated with a new screen?
This is not an appropriate use of updateUI(), which "Resets the UI property to a value from the current look and feel." As the example itself may be unreliable, consider studying another. GoogleOlympiad, for example, sets a label's icon using a (cached) image.
ImageIcon image = getImage(index);
imageLabel.setIcon(image);
(source: drjohnbmatthews at sites.google.com)
As per comments by ziggy (glad it helped)
Have a look at the PropertyChangeListeners that appear to be added in the code. In particular the propertyChange(PropertyChangeEvent e) method is where the code which changes the content will be present.
+1 to trashgod nice example/advice as always
I am having a set of panelbar Items which need to have a image as label and this image will change when onexpand and shrunck of the panel .
please help me in resolving this issue
I don't see any such options from here, But you can always play with raw HTML and set image there.
First, define two CSS classes: one for the normal state (I call it panelBarClosed), the second one for the opened state (panelBarOpened), and set the image as the background:
.panelBarClosed {
background: url('/path/to/images/closed.png');
}
.panelBarOpened {
background: url('/path/to/images/opened.png');
}
Now, on your <rich:panelBarItem>, set the first class:
<rich:panelBarItem headerClass="panelBarClosed" headerClassActive="panelBarOpened">
...
</rich:panelBarItem>
I am not sure if this is enough or not (I am not able to test it right now).
If this still is not working, this component provides two other attributes that can be useful in your case: onenter and onleave. The first event is fired when you "enter" the panel bar item (i.e. you open it), the second one when you leave it. So the idea is to change the CSS class of the component on this events:
<rich:panelBarItem ...
onenter="jQuery(this).removeClass('panelBarClosed').addClass('panelBarOpened');"
onleave="jQuery(this).removeClass('panelBarOpened').addClass('panelBarClosed');">
...
</rich:panelBarItem>
(again, I didn't test it, so maybe this solution should be corrected a little)