Hi guy I just started learn some JavaFX and I made a simple product TableView program which you can add and delete items. the items include name price and quantity.
I tried to prevent a bug so I did everytime the name\price\quantity fields are empty the add button will be disabled.
addButton = new Button("Add");
if(name.getText().isEmpty()&& price.getText().isEmpty() && quantity.getText().isEmpty()) {
addButton.setDisable(true);
} else {
addButton.setDisable(false);
addButton.setOnAction(e-> addButtonClicked());
}
The button is indeed disable but when I input some data to the field it remain disable.
I would like if someone can help me figure it out.
srry for the broken english ;)
Ok I fixed this, if someone got the same issue this is the solution :
addButton = new Button("Add");
addButton.disableProperty().bind(
name.textProperty().isEmpty()
.or(price.textProperty().isEmpty())
.or(quantity.textProperty().isEmpty())
);
Related
I am having a weird problem on my Vaadin app. I have a screen with two separate unbuffered grids.
The user is able to edit the data in those two grids and then click a "Save" button to save the changes made.
My problem is that I want to close the editors when the user clicks on "Save".
I tried the following code:
private void closeEditors() {
if (tab1.getEditor().isOpen()) {
tab1.getEditor().closeEditor();
}
if (tab2.getEditor().isOpen()) {
tab2.getEditor().closeEditor();
}
}
I don't understand why this code doesn't work, editors stay opened. I also tried calling the cancel method but in vain.
I am using Vaadin 14.
I am posting this here with not much hope of finding an answer, this problem seems really precise.
But with any luck, maybe someone has experienced a similar issue ?
Maybe there is another glitchier way of forcing my editors to close ?
Any suggestion would be of great help, thanks in advance for anything you could think of !
EDIT: a little more code
This is the grids:
private Grid<Map<String, String>> tab1;
private Grid<Map<String, List<String>>> tab2;
This is the save function
public void saveData() {
saveDataFromTab1();
saveDataFromTab2();
try {
ServicesProxyImpl.getInstance().updateInBD(someObject);
saveButton.setEnabled(false);
cancelButton.setEnabled(false);
closeEditors();
Dialog dialog = VaadinComponentUtils.generateDialog(Constantes.MSG_SAVE_OK);
dialog.open();
} catch (JAXBException e) {
e.printStackTrace();
Dialog dialog = VaadinComponentUtils.generateDialog(Constantes.MSG_SAVE_KO);
dialog.open();
}
}
And this is the save button:
public Button getSaveButton() {
Button saveButton= VaadinComponentUtils.generateButton("Save",
VaadinIcon.CHECK_CIRCLE_O, null, true);
saveButton.setEnabled(false);
saveButton.addClickListener(event -> saveData());
return saveButton;
}
EDIT 2:
I have noticed something, when I click on an element of one of my two grids, I want the editor to open for that specific element and I want to close the editor on the other grid (the one not concerned by the modification). This works ! My grids behave like I want. It seems I am only losing control over my editors after I have actually modified one of the cells and clicked on my save button.
The isOpen function returns false on both grids after I call my closeEditors function, so it seems the grid thinks its editor is closed but it is still opened on my UI.
EDIT 3: I have found a workaround
Well, I have solved my problem by adding a close event listener on both my grids and calling resetGrids when the close event is fired. This function simply removes the grids from the UI, fetches the data to be displayed and then adds the grid one again, both editors being closed. I guess it solves my problem but I would have wanted to understand what was going on...
private void closeEditors() {
tableauHoraires.getEditor().addCloseListener(e -> resetGrids());
tableauRamassagePorteAPorte.getEditor().addCloseListener(e -> resetGrids());
if (tableauRamassagePorteAPorte.getEditor().isOpen()) {
tableauRamassagePorteAPorte.getEditor().closeEditor();
}
if (tableauHoraires.getEditor().isOpen()) {
tableauHoraires.getEditor().closeEditor();
tableauHoraires.getEditor().refresh();
}
}
Make sure that the objects in your grid have proper equals and hashcode methods and that the field(s) being edited do not influence them.
I use the PK from the database.
Friends
I am a beginner and trying to develop a system level java swing software.
I have 2 JRadio buttons viz A & B in a RadioButton group bg.
I want to keep the radio button selection after restart or until further selection.
Searched for this long in net but getting code for PHP,HTML etc.
Somebody please help me.
rdbtA = new JRadioButton("A");
contentPane.add(rdbtA);
rdbtB = new JRadioButton("B");
contentPane.add(rdbtB);
ButtonGroup bg = new ButtonGroup();
bg.add(A);
bg.add(B);
When you start your application all the graphic components ar re-created, so you have to save the selection in some way when you close your program or when the selection changes (the easiest is to save your choice in a file) and restore it when the software is started (after the buttons creation).
Let me explain this in code:
rdbtA = new JRadioButton("A");
contentPane.add(rdbtA);
rdbtB = new JRadioButton("B");
contentPane.add(rdbtB);
/*
1. If exists a save-file, open it (else, ignore 2. and 3.)
2. read the value of previous A and previous B
3. Set these values to rdbtA and rdbtB
*/
//Rest of the code
I'm working on a school project, but I'm having a hard time. I need to check if a combobox is selected or not in JavaFX, but I can't find the solution. I hope someone can help me out.
if (View.getPriority().getItems().size() <= 0) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setContentText("test");
alert.show();
This is my code. I'm trying to access my combobox from a getter in my View-class.
If you have a reference to it:
boolean isSelected = !myComboBox.getSelectionModel().isEmpty();
Without having seen your code, I assume you are looking for combobox.isShowing()
So, i'm asking cause i searched and didn't found nothing about this, i don't know if i'm only searching it wrong.
I'm building a POS (Point of Sale) for my final School work but instead off adding the buttons manually i wanted to make an interface for the admn where he could add the buttons to the main project (ex. I want to add the button for Meat, Fish, etc.)
It's much likely to be easy to do it, my other doubt becomes with, if the button is generated how it will be called so i can use it later on?
With the NetBeans form designer you can see what code must be created.
Then instead of jButton1, jButton2 use List<JButton> buttons = new ArrayList<>();
In the initComponents (or after its call) create the buttons dynamically, using some list with button data: caption Meat / Fish / ... and so on. These data could come from a file you generated, so they are persist even if quitting the application.
A file can be read as:
Path path = Paths.get("buttons.txt");
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
for (String line : lines) {
String[] words = line.split(";\\s*");
if (words.length > 2 && words[0].equals("button")) {
JButton button = new JButton(word[1]);
button.addActionListener(this); ...
... add(button);
buttons.add(button);
}
}
I think you shouldn't generate new buttons. The best way is to hide the buttons you've created by calling button.setVisibility(View.Gone). So just create buttons and call setVisibility(View.Gone) in onCreate. And where needed make them visible by calling button.setVisibility(View.visible).
I am unable to press 'Go' button on searching something on Nexus 7' tablet. We don't have any text or content description for the 'Go' button on the keyboard. I tried using following -
//Search something say "fun"
new UiObject(new UiSelector().text("Enter URL or Search & Win")).setText("fun");
getUiDevice().pressEnter();
OR
getUiDevice().pressSearch();
Also tried :
getUiDevice().pressKeyCode(66); //for enter
getUiDevice().pressKeyCode(84); // for search
But this is not working.
Could anyone help me out with this.
Thanks
Try using the button attribute with reference to index.
i.e :
UiObject cancelButton = new UiObject(new UiSelector().className("android.widget.Button"));
To click on "Done" button with UIAutomator just try below code
use
just make sure that correct layout in which input keyboard is open is used
UiObject(new UiSelector().resourceId(LAYOUTID)).clickBottomRight();