I want to invoke the keyListener and get the keyCode while the dialog is being shown. I have tried extending Dialog and overrided the keyReleased() with no success. Below is my code, what went wrong?
public class MyDialog extends Dialog{
public void keyReleased(int keyCode) {
super.keyReleased(keyCode); //To change body of generated methods, choose Tools | Templates.
System.out.println("Keycode in Dialog: "+keyCode);
}
}
And in my form, I am using the custom Dialog like below:-
MyDialog dialog = new MyDialog();
dialog.show("INFO", "TEST CONTENT", "OK", "CANCEL");
You aren't using your dialog.
show(String, String, String, String) is a static method not an instance method so a new dialog instance is created and shown.
You need to use show() which is an instance method (or some other instance method like showDialog), but then you will have to actually add the components and "construct" your dialog.
Related
I have this problem: I can send data or a value to a function from a page or an API but razer component doesn't show the value; actually, it doesn't render new values.
Here's my example function:
public string p="";
public void myMethod(string a)
{
p=a;
}
Here's my HTML tag:
<p>#p</p>
When I click the button from an other page, myMethod will be called like this:
private void buttonClick()
{
new NavMenu().myMethod("Test text");
}
The button click is in a page and NavMenu is a component. I debug this and the value of 'p' successfully changed but the page does not show new value.
Actually I tried this code but nothing happened:
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(p));
What should I do to display new values without refreshing the page?
I want to add the popup to an existing functionality of backoffice. When a user click on the icon a popup will be populated with a text box and submit button.
I have tried many things but still can't find any proper solution. Help me in that to resolve the issue.
Create a new class that extends org.zkoss.zul.Window Class :
public class CustomWindow extends Window {
}
Then create a render method and add your components :
public class CustomWindow extends Window {
public void render(WidgetInstanceManager wim) {
initComponent(wim);
final Vlayout container = new Vlayout();
final Labeltext =new Label("text");
final Button button = new Button("button");
container.appendChild(button);
container.appendChild(text);
this.appendChild(container);
setClosable(true);
}
}
Then you can open your custom window with :
CustomWindow customWindow = new CustomWindow ();
customWindow.render(getWidgetInstanceManager());
customWindow.setParent("add parent component here");
customWindow.doModal();
Adapt the code to correspond more to your needs.
Hope this helps.
I’m a beginner, I can’t pass this level, please help.
I have a lot of forms with TextField (cust_no, cust_name), each with a button on the right,
press the button
A dialog can be display custom record, after selecting the required customer,
Write the selected cust_no, cust_name back to the Text_Field of Form.
I hope to write dialog as a public class, so that many class Forms can use this function, and can also smoothly write cust_no and cust_name back to their respective Form TextField.
In addition to backfilling cust_no,cust_name TextField for some Forms, some also need to query the consumption amount and write back the specified cust_amt TextField.
My trouble is that form button.addClickListener open a dialog,
Dialog’s Button_OK.addClickListener cannot know how I want to write back Form TextField and some have special query mechanisms, how to customize
Without seeing exactly how your code is structured, I can only give a quite generic answer. What you need is typically that something associated with the button for opening the dialog can know what to do with the result from the dialog, and it can also configure the dialog's OK button to carry out that action.
public class HelloWorldView extends VerticalLayout {
public HelloWorldView() {
TextField customerNumberField = new TextField("Customer number");
TextField customerNameField = new TextField("Customer name");
Button nameDialogButton = new Button("Open dialog", dialogOpenClick -> {
showDialog(customer -> {
customerNumberField.setValue(customer.getNumber());
customerNameField.setValue(customer.getName());
});
});
add(customerNumberField, customerNameField, nameDialogButton);
}
private void showDialog(Consumer<Customer> selectionAction) {
Select<Customer> customerSelect = new Select<>(new Customer("1", "Customer 1"),
new Customer("2", "Customer 2"));
customerSelect.setTextRenderer(customer -> customer.getName());
Dialog dialog = new Dialog();
dialog.add(customerSelect);
dialog.add(new Button("Select customer", click -> {
Customer selectedCustomer = customerSelect.getValue();
if (selectedCustomer != null) {
selectionAction.accept(selectedCustomer);
}
dialog.close();
}));
dialog.open();
}
}
I have an Android application with a dialog and a few buttons inside.
I want to reuse the dialog for different purposes and looking for a way to call the button from a separate class and define an action event for it.
Creating a test class, I managed to define an action event for a button inside a form, but the same code does not work for a button inside a dialog, and I can't get my head around why it is not working for the dialog.
Below is what I already have. Any suggestions would be appreciated.
public Class One {
Test test = new Test();
test.testOne(); // this is working : button prints
test.testTwo(); // this is not working : button does not print
buttonTest = test.getTestButton();
buttonTest.setText("Hello World"); // not working for a button in a dialog
buttonTest.addActionListener(l-> { // prints when the button in a Form
System.out.println("try"); // does not print when the button is in a dialog
});
}
public class Test {
Dialog dialog = new Dialog();
Form form = new Form();
Button button;
public void testOne() {
button = new Button("Test");
form.add(button);
form.show();
}
public void testTwo() {
button = new Button("Testing");
dialog.add(button);
dialog.show();
}
public Button getTestButton () {
return button;
}
}
You add the action listener after showing the form and dialog. This isn't a problem for the form since the forms show method will continue. But a dialogs show() method will block.
Two solutions:
Move the listener binding higher in the code (before the show) that would be a problem since the button doesn't exist yet so you will need some refactoring.
Change the show() call on the dialog to showModless()
I would like to create a dialog without the OK/Cancel buttons. I know that if you override the createButton method, this can be achieved.
What do you think of overriding the createButtonBar method to return null if the button bar is not required at all? This would save some code.
Overriding createButtonBar is going to produce errors if you return null for the result composite as the Dialog code expects it to not be null.
You can override createButtonsForButtonBar and not create any buttons. It looks like Dialog always checks that individual buttons exist.
You can remove the space used by the buttons composite like this:
#Override
protected void createButtonsForButtonBar(final Composite parent)
{
GridLayout layout = (GridLayout)parent.getLayout();
layout.marginHeight = 0;
}
If you want to have the only one "Close" button on your dialog, you can do it so:
#Override
public void create() {
super.create();
getButton(IDialogConstants.OK_ID).setVisible(false);
getButton(IDialogConstants.CANCEL_ID).setText("Close");
}