<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();
Related
I want to make applcation where you can add students and then assign to each one of them 20 books.
I have 3 windows:
Main windows (JFrame)
List of books (JDialog)
Add a book (JDialog)
I have JFrame where I can see list of all students, then I click on "List of books" where I can see the list of all books in database (.txt file). So when I click on that button in JFrame, I open JDialog, that works fine. But now I want to add some books to the list, so I click on button "Add a book" in "List of Books" JDialog. So I just want to open another JDialog a top of previous JDialog.
So I the window "List of books" (which I opened from Main window) I want to open windows "Add a book".
Now when I do it by the same method as I open JDialog from JFrame, it shows error :
private void pridatKnihuJButtonActionPerformed(java.awt.event.ActionEvent evt) {
addBookJDialog newwindow = new addBookJDialog(this, true);
newwindow.setLocationRelativeTo(null);
newwindow.setVisible(true);
}
It shows :
Incompatible types: addBookJDialog cannot be converted to Frame.
Is there a simple way to do this ?
I'm creating those windows in NetBeans design function.
I found a few topics about opening some JDialog on another JDialog, but I didnt understand how to do it :/ There are 3 lines of code that opens another JDialog. Is there a way to just simple open it ?
Thanks.
Ok. I found the answer... or more likely, I finally understood the code everyone was posting :D 2 hours of looking for this :D
If someone have same question. The answer is:
When you click on button in your dialog button, then head to the ActionPerformed section of that button (double-click on that button in NetBeans design section).
and write this :
JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this);
<target dialog> <optional name> = new <target dialog>(frame,true);
<optional name (but same as above)>.setLocationRelativeTo(null);
<optional name (but same as above)>pridatzaznam.setVisible(true);
Import what is needs to be imported and there you go.
It'll probably need these two:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
Example :
JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this);
dialogIWantToOpen openthis = new dialogIWantToOpen(frame,true);
openthis.setLocationRelativeTo(null);
openthis.setVisible(true);
Will open a dialog atop of your current dialog, but only if your current dialog was opened from JFrame.
If you want to open a dialog atop a dialog atop a dialog etc... it will probably need some editation after (JFrame) where
SwingUtilities.getWindowAncestor(this);
will probably have to be something like
SwingUtilities.getWindowsAncestor(SwingUtilities.getWindowAncestor(this));
So this will open a dialog, that was opened from a dialog that was opened from a dialog that was opened from a JFrame. But I'm not sure if it will work. Didnt tried that.
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.
i recently explored JavaFX and came across a simple login form executing the login via php script.
Based on the result the login form indicates an error label or redirects to a new scene.
During the actual login progress i want to show an progress bar which i exchange (visibility toggle) with an error label whenever the login did not succeed.
For some reason the progress bar jumps to a new position after the label appeared once.
Video showing the bug behavior:
Video of the issue
Minimal example to reproduce this behavior (JDK8, Language level=8):
Code sample
Well the component is jumping because when your are applying text to the Label, the width of the StackPane is getting increased and the ProgressBar gets shifted to the CENTER.
For future references, you can check similar phenomenon by applying a style to the StackPane or any other Layout
<StackPane style=" -fx-border-color:black;
-fx-border-width: 1; -fx-border-style: solid;">
To avoid this, you will have to wrap the ProgressBar in a HBox and set the alignment of the HBox
...
<Label id="login-status-label" fx:id="loginStatusLabel" />
<HBox alignment="CENTER_RIGHT">
<ProgressIndicator id="login-status-progress-indicator"
fx:id="loginStatusProgressIndicator" prefHeight="15.0"
prefWidth="15.0" visible="false"/>
</HBox>
...
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 ;)
I am developing GUI in an application (which is based on Spring framework) using Swing. In one of the screens, we have several JButtons, JLabels, JFormattedtextFields and JRadioButtons in a panel.
The question is:
1). When I press the tab button from the keyboard, the control does not goe to the JRadioButton field (though it goes to other components before and after it). It does not appear on these radio buttons (a serious issue with the application). How to fix this.
2).Also to set the text(label) for each radio buton, i have to do in separate labels:
<label text="Raiding" constraints="21,1" font="Arial-PLAIN-12" />
<buttongroup>
<radiobutton id="raidingYesID" font="Arial-PLAIN-12"
opaque="false" constraints="22,1" label="Yes"/>
<label text="Yes" constraints="23,1" font="Arial-PLAIN-12" />
<radiobutton id="raidingNOID" font="Arial-PLAIN-12"
selected="true" opaque="true" constraints="24,1"/>
<label text="No" constraints="25,1" font="Arial-PLAIN-12" />
</buttongroup>
I tried to do it in java, but the labels did not appear:
raidingYesID.setLabel("Yes");
raidingYesID.setName("Yes");
raidingNOID.setText("No");
none of them made any difference, but i could get the label on console by using:
System.out.println(raidingYesID.getLabel());
do suggest any solutions...
For your second question: use setText() to set the JRadioButton text and use getText() to get it back. The button text can also be set in the constructor.