/** * Creates a WButton with the specified text. * * @param text the button text, using {@link MessageFormat} syntax. * * <pre> * // Will create a button with the text "Hello world" * new WButton("Hello world"); * </pre> */ public WButton(final String text) { this(); setText(text); }
@Override public void execute(final ActionEvent event) { boolean disabled = !plainBtn.isDisabled(); plainBtn.setDisabled(disabled); linkBtn.setDisabled(disabled); disableBtn.setText(disabled ? "Enable buttons" : "Disable buttons"); } });
/** * {@inheritDoc} */ @Override public void updateComponent(final Object data) { MyData bean = (MyData) data; name.setText(bean.getName()); name.setActionObject(bean); count.setText(String.valueOf(bean.getCount())); incBtn.setActionObject(bean); decBtn.setActionObject(bean); }
button.setText(SHARED_TEXT);
@Test public void testAccessKeyHandling() { String buttonText = "ABCDE abcde"; WButton button = new WButton(buttonText); button.setAccessKey('E'); // reset shared button text. Access key should be automatically reset. button.setText("Test"); // override tool tip. String myToolTip = "My ToolTip"; button.setToolTip(myToolTip); Assert.assertEquals("Unexpected ToolTip text", myToolTip, button.getToolTip()); }
/** * Attempts to set the text contained in the body component. This works only for simple components types: * <ul> * <li>{@link WButton}</li> * <li>{@link WLink}</li> * <li>{@link WLabel}</li> * <li>{@link WText}</li> * </ul> * * @param text the new body text, using {@link MessageFormat} syntax. * @param args optional arguments for the message format string. */ public void setText(final String text, final Serializable... args) { WComponent body = getBody(); if (body instanceof WText) { ((WText) body).setText(text, args); } else if (body instanceof WLabel) { ((WLabel) body).setText(text, args); } else if (body instanceof WButton) { ((WButton) body).setText(text, args); } else if (body instanceof WLink) { ((WLink) body).setText(text, args); } else if (body == null) { setBody(new WText(text, args)); } }
@Override public void executeOnValid(final ActionEvent event) { String[] data = new String[]{ formatName(searchFS.getFirstName(), searchFS.getLastName()), formatName(searchFS.getFirstName() + "-Two", searchFS.getLastName()), formatName(searchFS.getFirstName() + "-Three", searchFS.getLastName()) }; layout.setVisible(true); selectButton.setVisible(true); rbSelect.setOptions(data); rbSelect.resetData(); searchButton.setText("New Search"); } });
/** * this is were the majority of the work is done for building the button. Note that it is in a container that is * reset, effectively creating a new button. this is only done to enable to dynamically change the button to a link * and back. */ private void applySettings() { buttonContainer.reset(); WButton exampleButton = new WButton(tfButtonLabel.getText()); exampleButton.setRenderAsLink(cbRenderAsLink.isSelected()); exampleButton.setText(tfButtonLabel.getText()); if (cbSetImage.isSelected()) { exampleButton.setImage("/image/pencil.png"); exampleButton.setImagePosition((ImagePosition) ddImagePosition.getSelected()); } exampleButton.setDisabled(cbDisabled.isSelected()); if (tfAccesskey.getText() != null && tfAccesskey.getText().length() > 0) { exampleButton.setAccessKey(tfAccesskey.getText().toCharArray()[0]); } buttonContainer.add(exampleButton); }
/** * Creates an XsltTestComponent. */ public XsltTestComponent() { this.setLayout(new FlowLayout(Alignment.VERTICAL)); add(xsltTextField); add(inputTextField); add(outputTextField); WButton go = new WButton(); go.setText("Go"); go.setAction(new Action() { @Override public void execute(final ActionEvent event) { runTransform(); } }); add(go); console.setColumns(100); console.setRows(30); add(console); }