I have a zul page with a list of menuitems pointing to different zul pages. I would like that, when a menu item is clicked, the page pointed out by that menuitem has to be refreshed. I have tried with the Events.sendEvent() approach, but it doesn't work. What's the best approach to do it? Thanks in advance. here is the code:
<menuitem id="Car" label="Car">
<attribute name="onClick">
{
inc.setSrc("/zul/car.zul");
Events.sendEvent(reload, event);
}
</attribute>
</menuitem>
Don't use <include /> for zul pages better do it like this:
...
<div id="currentSite" width="800px" heigth="600px" />
...
and then add onClick listeners in java, btw don't use scripts like yours in production.
#Listen("onClick = #Car")
public void carClicked(Event ev){
// clear old content
currentSite.getChildren().clear();
// add the new
Executions.createComponent("/zul/car.zul", currentSite, null);
}
You have more control and less pain ;)
Related
I've been searching for a while and I haven't been able to get what I wanted to do. I've been using the javafx framework to switch fxml in javafx in this thread 'Loading new fxml in the same scene' with some success. I mean, I have a main window, and this window have two different areas, the MAIN area, and the CONTENT area.
The MAIN area will remain the same in the whole application, but the CONTENT area, will be changing constantly. My MAIN area has just a toolbar, and depending which button in the toolbar you click, the fxml (and the behavior) in the CONTENT area will change.
I already have that behavior and it works like a charm using that said framework.
The thing is, that I want that all my CONTENT areas could have their own MAIN areas too, and an own CONTENT areas too. And depending on what you do in that second MAIN areas, the fxml and the behavior in that second CONTENT areas changes too.
I don't know if the framework I'm using is enough and if I will be able to get what I want to do using it.
Do you know another different framework that could help me to get that functionality?
Thanks a lot in advance!
Every .fxml that you load can have its own controller. Every controller can have custom action and loading code just like your main one does.
Basically, JavaFX is modular. If something is possible in your main pane, then it's possible in all its children too.
Generally, in UI-based frameworks, it is a wise idea to keep a hierarchy of controllers that mirrors the hierarchy of their respective components. If you want to get the child controller for the child element (for example, in order to pass the reference to the parent controller), then you can't rely on the FXML.load() shortcut, you have to use the longer syntax of:
FXMLLoader loader = new FXMLLoader(getClass().getResource("your.fxml"));
YourPaneType pane = loader.load();
YourControllerType controller = loader.getController();
You can load all of your content using fx:include and make them visible based on your needs.
<AnchorPane fx:id="root">
<children>
<!-- initial content -->
<fx:include fx:id="content1" source="content1.fxml" />
<!-- other content we want to pre-load -->
<StackPane visible="false" managed="false">
<children>
<fx:include fx:id="content2" source="content2.fxml" />
<fx:include fx:id="content3" source="content3.fxml" />
</children>
</StackPane>
</children>
</AnchorPane>
and in the controller
#FXML
Pane root;
#FXML
Pane content1;
#FXML
Pane content2;
#FXML
Pane content3;
#FXML
NestedContentController content1Controller;
#FXML
NestedContentController content2Controller;
#FXML
NestedContentController content3Controller;
public void showContent1() {
root.getChildren().setAll(content1);
}
public void showContent2() {
root.getChildren().setAll(content2);
}
public void showContent3() {
root.getChildren().setAll(content3);
}
(The initially hidden content could also be defined outside the object hierarchy in an <fx:define> element, but then SceneBuilder doesn't provide an option to reveal the included file.)
I have been developing an app in Android. I have created a menu with some static elements:
<menu
android:id="#+id/submenu">
<item android:id="#+id/create_new"
android:title="eganaude" />
<item android:id="#+id/open"
android:title="skema" />
</menu>
and I have a rule to add other elements dynamically:
menu_global.add(0, new_hash_value, 0, text);
However, this way each time I restart the app, I should add again the elements to the menu. So I would like the new elements added dynamically to appear at each restart. Is there a way to implement this behaviour?
I recommend you to use an internal database to keep your information, is easy to implement it, look at this link with information:
https://developer.android.com/guide/topics/data/data-storage.html#db
The only way to do that is to save the new added menu items to database or shared preferences or in a file and then later read/load the items and add them to the menu
I'm willing to create a android quiz app. I've done all things and my app is completed but I'd like to make the quiz option buttons to change its color when it is pressed by user in order to show whether the answer is correct or wrong.
I'd like to show red color button on clicking wrong option and green on correct option .please help me with a simple code that I can embedd in my presaved app java files.
You can try this:
someButton.setBackgroundColor(Color.RED); // Wrong option
someButton.setBackgroundColor(Color.GREEN); // Correct option
Refer to View#setBackgroundColor(int) and Color.
A Button is a sub-class of View.
You can use the combination of android:state_selected and the android:state_enabled properties of the StateListDrawable to achieve the effect through xml.
Your button background can be defined as a drawable below
<selector>
<item android:drawable="#drawable/default_button_background" />
<item android:state_selected="true" android:state_enabled="true" android:drawable="#drawable/correct_answer_background" />
<item android:state_selected="true" android:state_enabled="false" android:drawable="#drawable/wrong_answer_background"
</selector>
and in your code. On Click of the button add this code
boolean isAnswerCorrect = //your logic to check if answer is correct or not
clickedButton.setEnabled(isAnswerCorrect);
In the following approach, you would need to create two image files for backgrounds on the button to represent correct or false.
Create a folder called Drawable under res and place these two image files in there, then call them as seen below like, R.drawable.filename.
buttonCheckAnswerObject = (Button)findViewById(R.id.buttonCheckAnswer);
buttonCheckAnswerObject.setOnClickListener(new OnClickListener() {
#Override
public void onClick(final View v) {
boolean userAnswer;//check if correct
if (userAnswer){
v.setBackgroundResource(R.drawable.button_correct_answer_color);
}
else {
v.setBackgroundResource(R.drawable.button_false_answer_color);
}
}
});
enter code here
I have created a sample fx application with fxml using the scene buidler.
I have mapped an action handler on scene builder and write it on the java controller class. By clicking proceed button the screen will change to another screen. But sometime screen will get stuck at that time user will click proceed button multiple time, so the system will crash.
I have added disable property of button at the beginning of action controller, but it is not happening. How to block multiple event click event or just disable button at once clicked?
#FXML
public void onBtnProceedClick() {
btnProceed.setDisable(true);
// other part of method.
}
FXML
<Button fx:id="btnProceed" maxWidth="1.7976931348623157E308" mnemonicParsing="false"
onAction="#onBtnProceedClick" prefHeight="40.0" prefWidth="-1.0"
styleClass="btnProceed" text="" GridPane.columnIndex="1"
GridPane.rowIndex="0"
/>
The event has a getClickCount(). You can add a check to say if getClickCount() > 1 then do nothing and return.
<window title="My First Window" border="normal" width="200px" visible="false" mode="modal">
Hello, World!
</window>
When running this example i expect that there is no popUp window shown as visible="false" ....
But i do get a popUp ... what am i missing ?
When i remove mode="modal" it runs fine. So how do we control visible property on window with mode = "model"
Zk fiddle example
Why i want to do the above described;
I am following the mvvm model so when something happens in app i want to show a popup by just making the popup window visible that is why i want to create a modal window that is immediately dismissed and show it later
Gut feeling is that what you're asking doesn't make sense. A modal window must have focus and must be dismissed before you can move on. So if it's there, how can it not be visible?
I think rather than showing a Modal Window I will suggest use Notification
Clients.showNotification(msg); // display a global notification box
Clients.showNotification(msg, component); // display a notification box pointing to a component
And in your code use code like this and see what will happen
<window title="My First Window" border="normal" width="200px" mode="modal" visible="false">
Hello, World!
</window>
<window id="win" visible="false">
</window>
when u need your window to be visible just do:
win.doModal();