CheckBox(String str) Constructor is undefined - checkbox

I am trying to make a CheckBox using javafx-8 but the constructor which intialises the label associated with it that is CheckBox(String str) is not defined similarly the setSelected method and setText methods are not defined in the library.
I have updated java to the latest version Java SE 8u131 but the problem is still there.
Here's the code
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;import javafx.stage.Stage;
public class CheckBox extends Application {
Stage window;
Scene scene;
Button button;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("JavaFX");
//Checkboxes
CheckBox box1 = new CheckBox("apples");
CheckBox box2 = new CheckBox("Tuna");
box2.setSelected(true);
//Button
button = new Button("Order Now!");
button.setOnAction(e -> handleOptions(box1, box2));
//Layout
VBox layout = new VBox(10);
layout.setPadding(new Insets(20, 20, 20, 20));
layout.getChildren().addAll(box1, box2, button);
scene = new Scene(layout, 300, 250);
window.setScene(scene);
window.show();
}
//Handle checkbox options
private void handleOptions(CheckBox box1, CheckBox box2){
String message = "Users order:\n";
if(box1.isSelected())
message += "Bacon\n";
if(box2.isSelected())
message += "Tuna\n";
System.out.println(message);
}
}
Here's the Error log
CheckBox.java:24: error: constructor CheckBox in class CheckBox cannot be applied to given types;
CheckBox box1 = new CheckBox("apples");
^
required: no arguments
found: String
reason: actual and formal argument lists differ in length
CheckBox.java:25: error: constructor CheckBox in class CheckBox cannot be applied to given types;
CheckBox box2 = new CheckBox("Tuna");
^
required: no arguments
found: String
reason: actual and formal argument lists differ in length
CheckBox.java:26: error: cannot find symbol
box2.setSelected(true);
^
symbol: method setSelected(boolean)
location: variable box2 of type CheckBox
CheckBox.java:35: error: method addAll in interface ObservableList<E> cannot be applied to given types;
layout.getChildren().addAll(box1, box2, button);
^
required: Node[]
found: CheckBox,CheckBox,Button
reason: varargs mismatch; CheckBox cannot be converted to Node
where E is a type-variable:
E extends Object declared in interface ObservableList
CheckBox.java:46: error: cannot find symbol
if(box1.isSelected())
^
symbol: method isSelected()
location: variable box1 of type CheckBox
CheckBox.java:49: error: cannot find symbol
if(box2.isSelected())
^
symbol: method isSelected()
location: variable box2 of type CheckBox
I am using eclipse ide but its not problem of that too because i have tried compiling it through ubuntu's shell.
How should i rectify this ?
Thanks in Advance!

CheckBox is your class name,so rename your class name and import javafx checkbox
import javafx.scene.control.CheckBox;
or use fully qualified name like that.
javafx.scene.control.CheckBox box1 = new javafx.scene.control.CheckBox("apples");
javafx.scene.control.CheckBox box2 = new javafx.scene.control.CheckBox("Tuna");
In handleOptions() method
private void handleOptions(javafx.scene.control.CheckBox box1, javafx.scene.control.CheckBox box2) {

Related

How to create a pop-up with a Picker where the picker is immediately active and with a 'Skip' option?

I have a couple of places in my UI where the user clicks an action and then I'd like to show a pop-up with (something like) a Dialog to invite him/her to add optional information, e.g. use a Picker to enter a date.
The idea is that this popup should be as little intrusive as possible and require as few clicks as possible, so I was thinking something like a Dialog with an explanation text and a Picker already activated so the user can directly swipe to the right date and push Done, and also a [Skip] button to directly close the Dialog without entering anything.
However, I've tried many different solutions and the picker (even in Light mode) appears outside the Dialog and I can't get the Dialog to close when clicking Done in the Picker.
Does anyone have a suggestion on how this could be achieved?
Here's how I finally implemented it, using the non-public components used by the Spinners (so the class must be placed in com.codename1.ui.spinner). I also noticed an issue in DateSpinner3D which sets the time of day randomly (to the time of activation), which means it may alter a Date even if not edited, but I'll do a PR for that.
I've only implemented support for the Picker elements I currently use.
So not fully reusable/generic solution, but hopefully it can help show how it can be done if anyone runs into the same need.
I've added a screenshot (only test colors): [![enter image description here][1]][1]
package com.codename1.ui.spinner;
import com.codename1.components.SpanLabel;
import com.codename1.components.Switch;
import com.codename1.io.Log;
import com.codename1.ui.Button;
import com.codename1.ui.Command;
import com.codename1.ui.Container;
import com.codename1.ui.Dialog;
import com.codename1.ui.Display;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
import com.parse4cn1.operation.SetFieldOperation;
import java.util.Date;
public class PickerDialog {
Dialog dlg;
Command doneCmd;
int type;
DateTimeSpinner3D dateTimeSpinner;
DateSpinner3D dateSpinner;
DurationSpinner3D durationSpinner3D;
public static String DONE_BUTTON_TEXT = "Done";
public static String CANCEL_BUTTON_TEXT = "Cancel";
public PickerDialog(String title, String text, Object value, String cancelText, String doneText, int type) {
this.type = type;
dlg = new Dialog();
dlg.setDialogUIID("PickerDialog");
dlg.setTitle(title);
dlg.setLayout(BorderLayout.center());
Container cont = new Container(BoxLayout.y());
SpanLabel textSpanLabel = new SpanLabel(text);
textSpanLabel.setTextUIID("PickerDialogText");
cont.add(textSpanLabel);
switch (this.type) {
case Display.PICKER_TYPE_DATE_AND_TIME:
dateTimeSpinner = new DateTimeSpinner3D();
dateTimeSpinner.setValue(value);
cont.add(dateTimeSpinner);
break;
case Display.PICKER_TYPE_DATE:
dateSpinner = new DateSpinner3D();
dateSpinner.setValue(value);
cont.add(dateSpinner);
break;
case Display.PICKER_TYPE_DURATION:
durationSpinner3D = new DurationSpinner3D(DurationSpinner3D.FIELD_HOUR | DurationSpinner3D.FIELD_HOUR);
durationSpinner3D.setValue(value);
cont.add(durationSpinner3D);
break;
}
doneCmd = Command.create(doneText, null, (e) -> {
dlg.dispose();
});
Button doneButton = new Button(doneCmd);
Container buttonBar;
if (cancelText != null && !cancelText.isEmpty()) {
Button cancelButton = new Button(Command.create(cancelText, null, (e) -> {
dlg.dispose();
}));
buttonBar = BorderLayout.centerEastWest(null, doneButton, cancelButton);
} else {
buttonBar = BorderLayout.centerEastWest(doneButton, null, null);
}
dlg.getContentPane().add(BorderLayout.SOUTH, buttonBar);
dlg.getContentPane().add(BorderLayout.CENTER, cont);
}
/**
* return the value of the picker of the defined type (Date or
*
* #return
*/
public Object show() {
Command cmd = dlg.showDialog();
if (cmd == doneCmd) {
switch (type) {
case Display.PICKER_TYPE_DATE_AND_TIME:
return dateTimeSpinner.getValue();
case Display.PICKER_TYPE_DATE:
return dateSpinner.getValue();
case Display.PICKER_TYPE_DURATION:
return durationSpinner3D.getValue();
}
}
return null;
}
}
[1]: https://i.stack.imgur.com/ByvFK.png

Can I remove the 'carrot' (upside down triangle) created by the ComboBoxListViewSkin?

When implementing the java ComboBoxListViewSkin class to manage the popup listener of my ComboBox, this adds a 'carrot' to the upper left corner of the ComboBox (see below). If I remove this class implementation it goes away. I'm using the CombBoxListViewSkin's class popup listener to prevent the [SPACE] from selecting and closing the ComboBox when pressed which allows the [SPACE] character to be typed as part of an AutoComplete class.
This is all the code involved in managing and allowing the [SPACE] to work as part of AutoComplete class -and works great. I've tried searching the ComboBoxListViewSkin class for methods or properties that may prevent this, but nothing addresses this. I thought maybe the COMBO_BOX_STYLE_CLASS might offer something but everything really only manages the displaying, adding or removing items. Since the code below is the minimal necessary to recreate the issue, this will not perform the auto-complete function, but it demonstrates that removing and re-implementing the ComboBoxListViewSkin class causes the issue.... or appears to.
// Main method calling
public class Main extends Application{
public static void main(String[] args) {
launch();
}
public void start(Stage stage) throws Exception {
ComboBox cmb = new ComboBox();
cmb.getItems().setAll("One", "One Two", "One Two Three");
new ComboBoxAutoComplete(cmb);
Scene scene = new Scene(new StackPane(cmb));
stage.setScene(scene);
stage.setTitle("Test GUI");
stage.setWidth(300);
stage.setHeight(300);
stage.show();
}
}
// ComboBoxAutoComplete class with ComboBoxListViewSkin initialization
// Minimal of ComboBoxAutoComplete class constructor
import com.sun.javafx.scene.control.skin.ComboBoxListViewSkin;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.ComboBox;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import java.util.stream.Stream;
#SuppressWarnings("ALL")
public class ComboBoxAutoComplete<T> {
private ComboBox<T> cmb;
private String filter = "";
private ObservableList<T> originalItems;
private ComboBoxListViewSkin cbSkin;
public ComboBoxAutoComplete(final ComboBox<T> cmb) {
this.cmb = cmb;
originalItems = FXCollections.observableArrayList(cmb.getItems());
cbSkin = new ComboBoxListViewSkin(cmb);
// Aside from the variable declaration and initialization... this
// is the only ComboBoxListViewSkin code to handle the [SPACE]
cbSkin.getPopupContent().addEventFilter(KeyEvent.KEY_PRESSED, (event) -> {
if (event.getCode() == KeyCode.SPACE) {
filter += " ";
event.consume();
}
});
}
}
My expectation is for the ComboBox to look like all the other ComboBoxes in the application GUI. Although it is a minor issue, to the user I believe it may look like an issue with the application is going on.
Resolved: As Fabian suggested above, I added a cmb.setSkin(cbSkin) after the initialization and before the event filtering and it worked. Thought I would post so others would see it was resolved.
cbSkin = new ComboBoxListViewSkin(cmb);
cmb.setSkin(cbSkin); // <------------- ADDED
cbSkin.getPopupContent().addEventFilter(KeyEvent.KEY_PRESSED, (event) -> {
if (event.getCode() == KeyCode.SPACE) {
filter += " ";
event.consume();
}
});

Vaadin - How to convert a Grid column which has boolean value to Checkbox

I am using Vaadin 7.6.4 for my UI work. This has the following:-
I have a window which contains a grid with data in it. This window is actually a kind of a pop up[ which shows up when my main screen gets a click on the settings icon( not shown here). This is working fine( getting the UI screen to open the Vaadin window when the settings icon the main screen is clicked).
The problem is in showing the data as mentioned below.
This grid will have 4 columns for which the data comes from a bean container.
The first column is a boolean field with true/false getting displayed based on the data from the bean container.
I need to convert this boolean field column into a checkbox with true showing the field as a checkbox with a value selected. If the value is false, then show a checkbox which is not selected.
I am trying to do that as shown in the code below but I keep getting this checkbox name printed. I dont see the checkbox but the word "checkbox" printed in there?
This checkbox should be editable. The idea is that the user should be able to select some checkboxes and the ones selected should be shown in a panel ( not shown here). Thus, the checkbox has to be editable.
How do I fix this? The code for the window is shown below
package com.platform28.mybatis;
import java.util.List;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.data.util.GeneratedPropertyContainer;
import com.vaadin.data.util.PropertyValueGenerator;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Grid;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
#SuppressWarnings("serial")
public class ConfigPopUp extends Window {
VaadinUtils vaadinUtils = null;
public ConfigPopUp(List<TableColumnData> tblDataLst) {
vaadinUtils = new VaadinUtils();
// Some basic content for the window
VerticalLayout configLayout = new VerticalLayout();
configLayout.addComponent(new Label("Settings"));
configLayout.setMargin(true);
//configLayout.setWidth(null);;
setContent(configLayout);
//adding grid.
List<SettingsColumnData> settingsList = vaadinUtils.processSettingsList(tblDataLst);
final BeanItemContainer<SettingsColumnData> gridDataSource = new BeanItemContainer<SettingsColumnData>(SettingsColumnData.class, settingsList);
//change boolean value to checkbox.
GeneratedPropertyContainer gp = new GeneratedPropertyContainer(gridDataSource);
gp.addGeneratedProperty("columnDisplayed", new PropertyValueGenerator<CheckBox>() {
#Override
public CheckBox getValue(Item item, Object itemId, Object propertyId) {
boolean currentCheckBoxValue = (boolean) item.getItemProperty("columnDisplayed").getValue();
CheckBox chkBox = new CheckBox();
chkBox.setValue(currentCheckBoxValue);
return chkBox;
}
#Override
public Class<CheckBox> getType() {
return CheckBox.class;
}
});
Grid settingsGrid = new Grid(gp);
settingsGrid.setWidth("100%");
settingsGrid.setSizeFull();
settingsGrid.setColumnOrder("columnDisplayed", "columnName","columnShortName","columnDescription");
configLayout.addComponent(settingsGrid);
//configLayout.setExpandRatio(settingsGrid, 1);
// Disable the close button
setClosable(false);
HorizontalLayout hLayout = new HorizontalLayout();
hLayout.setSpacing(true);
hLayout.setMargin(true);
// Trivial logic for closing the sub-window
Button ok = new Button("Ok");
ok.addClickListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
close(); // Close the sub-window
}
});
hLayout.addComponent(ok);
// Trivial logic for closing the sub-window
Button cancelBtn = new Button("Cancel");
cancelBtn.addClickListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
close(); // Close the sub-window
}
});
hLayout.addComponent(cancelBtn);
configLayout.addComponent(hLayout);
// set pop up to center.
center();
// should be resizable
setResizable(true);
// should not be draggable
setDraggable(false);
//set it as modal window
setModal(true);
setWidth("50%");
setHeight("75%");
}
}
Ok, we used the SelectionMode.MULTI to show the selection of rows in there.
https://cdn.vaadin.com/vaadin-core-elements/latest/vaadin-grid/demo/selection.html
Still, I would love to learn more as to how we get the change done as shown in the question above.
Still looking for an answer to that.
Use a Renderer and a Converter, you don't need to use SelectionMode.MULTI.
An example of this is posted here.

Create UI components on page load

I am currently working on oracle adf task flows and regions and I want to create and update some UI components on page load and for this I am using method call activity as default.The problem is that I am getting null values following is my code in the bean that executes on the method call.
package view;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import oracle.adf.view.rich.component.rich.output.RichOutputText;
public class testBean {
public testBean() {
}
public String testMethod() {
// Add event code here...
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();
RichOutputText text = ( RichOutputText )root.findComponent( "r1:ot1" );
text.setValue( "Adding text on run time" );
return "product";
}
}
The set value method returning me null may be it is because the fragment product.jsff which is the view activity is not initiated and the output text with ot1 returning null.
The better approach to achieve the setting of value is to have a property in your bean say: textValue and then bind the value attribute of your ot1 with the property of the bean.
class TestBean{
private String textValue;
public String testMethod() {
textValue = "Adding text on run time";
}
public String getTextValue(){
return textValue;
}
}
Your JSPX would be:
<af:outputText id="ot1" value=#{beanName.textValue}" />

Caused by: org.openqa.selenium.NoSuchElementException: Element is not usable

I use Selenium Webdriver + Thucydides. When I try to use a checkbox (any state: isEnabled(), isDisplayed(), isSelected()), so an error will occur. I tried the different locators: by id, name, xpath. The checkbox is available in the page source. All other element on the page work correctly. I use DisplayedElementLocatorFactory.
My locators:
#FindBy(id = "remember")
// #FindBy(xpath = ".//*[#type='checkbox']")
// #FindBy(name = "_remember_me")
protected WebElement rememberMeCheckbox;
HTML-source of checkbox:
<label for="remember" class="remember"><div class="checker" id="uniform-remember"><span><input type="checkbox" value="1" name="_remember_me" id="remember" /></span></div>Remember me</label>
My function:
public void isLoginFormLoadedCorrectly()
{
String pageSource = driver.getPageSource();
System.out.println(pageSource);
String errorMessage = "";
if (!loginInput.isDisplayed())
errorMessage += "Username field is not displayed or not found\r\n";
if (!passwordInput.isDisplayed())
errorMessage += "Password field is not displayed or not found\r\n";
if (!submitButton.isDisplayed())
errorMessage += "Submit button is not displayed or not found\r\n";
if (!passwordRecoveryLink.isDisplayed())
errorMessage += "Password recovery link is not displayed or not found\r\n";
if (!rememberMeCheckbox.isDisplayed())
errorMessage += "Remember me check-box is not displayed or not found\r\n";
// if (rememberMeCheckbox.isSelected())
// errorMessage += "Remember me check-box is selected\r\n";
assertThat(errorMessage, errorMessage.equals(""), is(true));
}
Error:
net.thucydides.core.webdriver.WebdriverAssertionError: org.openqa.selenium.NoSuchElementException: Timed out after 30 seconds. Unable to locate the element
Caused by: org.openqa.selenium.NoSuchElementException: Timed out after 30 seconds. Unable to locate the element
Caused by: org.openqa.selenium.NoSuchElementException: Element is not usable
I had the same error trying to click on the checkbox.
I solved it by clicking element with tag <span>, not <input>.
In your example it can be found, for instance, like this (element one level higher than your checkbox):
#FindBy(xpath = ".//*[#type='checkbox']/..")
I cannot reproduce your issue:
#RunWith(ThucydidesRunner.class)
public class VerificationTest {
#Managed
public WebDriver driver;
#ManagedPages
public Pages pages;
#Test
public void testCheckbox(){
CheckBoxPage pg = pages.get(CheckBoxPage.class);
pg.openAt("http://www.echoecho.com/htmlforms09.htm");
assertTrue("checkbox is displayed", pg.ckbxElement.isDisplayed());
assertTrue("checkbox is selected", pg.ckbxElement.isSelected());
}
}
where
public class CheckBoxPage extends PageObject{
#FindBy(css = ".table8 input:checked")
public WebElement ckbxElement;
public CheckBoxPage(WebDriver driver) {
super(driver);
}
}
with both FindBys: org.openqa.selenium.support.FindBy and net.thucydides.core.annotations.findby.FindBy
Since all other elements work make sure:
it's not in iframe.
htlm is correct

Resources