How to write in a specific spot in TableView with JavaFX - java

I am in the process of self-training on the subject of graphic JavaFX
My goal is to be able to place an X in the corresponding box
I found several tutorials that explain how to write a partial or full row but only one field and depending on the column / row value ... I can't do it, I need help from the community to m 'open my eyes, so run my hoop lol
Thx in advance
Have a nice day/evening/night/morning

With GridPane, i found what i probably need :)
#FXML
protected void shootOnGrid(ActionEvent actionEvent) {
if (column.getText().isEmpty() || line.getText().isEmpty() ){
resultShoot.setText("There is some information missing");
} else {
resultShoot.setText(column.getText()+line.getText());
grid.add(new Text(line.getText()), 0,0);
}
}
Now, i need to work with thoses property :)
If i can name the Colomn and row...etc

Related

Vaadin unbuffered grids won't close

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.

How to correct a display problem when inserting a row in a JavaFX grid?

I want to insert a new JavaFX bean in a grid using an "insert" button. Everything is fine, except for a display problem. After insertion, a "ghost selection" is displayed lower in the grid, as shown in this screenshot. In this example, a fourth section bean was added and selected as requested. But a fake selection appears 10 lines under the last real bean, where no bean is set for this row.
Has anyone experienced this kind of behavior? Any clue how get rid of this ghost selection? Here is what the code for the insert button looks like:
#FXML
private Button insert;
...
insert.setOnAction(event -> {
JfxBean newBean = createBean();
tableView.getItems().add(newBean);
int index = tableView.getItems().indexOf(newBean);
tableView.getSelectionModel().clearSelection();
tableView.requestFocus();
tableView.scrollTo(index);
tableView.getSelectionModel().focus(index);
tableView.getSelectionModel().select(index);
};
According to javaFX-8 documentation, SelectionModel.java does not expose any focus() method. FocusModel.java does instead. Therefore JVM will fail to compile your presented code.
Below is a possible solution:
insert.setOnAction(event -> {
JfxBean newBean = createBean();
tableView.getItems().add(newBean);
int index = tableView.getItems().indexOf(newBean);
tableView.getSelectionModel().clearSelection();
tableView.requestFocus();
tableView.scrollTo(index);
// below line is the amendment
tableView.getFocusModel().focus(index);
tableView.getSelectionModel().select(index);
};
Finally, adding tableView.refresh() corrected this weird behavior. No more ghost selection.

Removal method works bindAutoCompletion () class TextFields library ControlsFX

I have in the text box that by choosing the combo box Binds respectively the text field with the specified data. The point is that after the first binding process, you can not remove the effect. I choose binding logins, this Binds me a text box with logins. Then I want Bind the e-mail, then I develop two lists, login and e-mail.
#FXML
public void setToSearch() {
if(comboSettingsSearch.getSelectionModel().getSelectedIndex() == 1)
TextFields.bindAutoCompletion(textSearchPerson, Database.loadLogins());
if(comboSettingsSearch.getSelectionModel().getSelectedIndex() == 5)
TextFields.bindAutoCompletion(textSearchPerson, Database.loadEmails());
}
enter image description here
Underneath logins, and on top of e-mail. Anyone know how to remove this effect?
If you do it like this,
#FXML
public void setToSearch() {
if(comboSettingsSearch.getSelectionModel().getSelectedIndex() == 1)
AutoCompletionBinding<String> acbLogin = TextFields.bindAutoCompletion(textSearchPerson, Database.loadLogins());
if(comboSettingsSearch.getSelectionModel().getSelectedIndex() == 5)
AutoCompletionBinding<String> acbEmail = TextFields.bindAutoCompletion(textSearchPerson, Database.loadEmails());
}
you can dispose the binding with
acbLogin.dispose();
acbEmail.dispose();
as far as I can tell from the HelloAutoComplete-example and the javadocs.
This is a late response to this post, however, I see that it apparently didn't work because it is not checked. It also didn't work for me but two weeks later I discovered why.
The proposed declaration and initialization above does not work if you include the type as part of the declaration. You need to remove the type from the declaration and then the .dispose() method will work.
This doesn't work:
AutoCompletionBinding<String> acbLogin = TextFields.bindAutoCompletion(textSearchPerson, Database.loadLogins());
This does:
AutoCompletionBinding acbLogin = TextFields.bindAutoCompletion(textSearchPerson, Database.loadLogins());
AutoCompletionBinding acb = TextFields.bindAutoCompletion(txtfield,arraylistobj);
acb=null;

ContentProposalAdapter prevent new line on select proposal

I use the ContentProposalAdapter to provide content assist to my StyledText fields. I wrote an adapter that implements IControlContentAdapter, IControlContentAdapter2 to support the StyledText. My problem is that, when I press return to insert the proposal the return key is inserted into the StyledText and after that the proposal is inserted.
Why are the UP and DOWN arrows not traversed, but the return key is.
How to prevent the return key from begin inserted into the StyledText field when used to select a proposal.
maybe the question is old, but as I googled and this Post nearly covered my problem, but without a solution, I thought to provide my solution I found now.
My Problem was exactly the same but the newline got inserted after the selected proposal.
Selecting the proposal via double click works just fine so I agreed with you that it´s probably the StyledTextWidget that gets notified about the Enter...
First I tried setPropagateKeys(false) on my ContentProposalAdapter, as the doc says it "indicates whether key events (including auto-activation characters) received by the content proposal popup should also be propagated to the adapted control when the proposal popup is open". But this does not work either.
What actually worked for me is the following:
I added an VerifyKeyListener to the StyledTextWidget and just filtered the Enter Event when the ProposalPopup is open. I thought that maybe wouldn´t work as the newline gets inserted after the proposal but on my program it works fine so it seems the closure of the proposal popup is done after the Enter Key is passed to the StyledTextWidget.
Heres the code:
styledText.addVerifyKeyListener(new VerifyKeyListener() {
#Override
public void verifyKey(VerifyEvent arg0) {
try {
KeyStroke k = KeyStroke.getInstance("Enter");
if(k.getNaturalKey() == arg0.keyCode && contentProposalAdapter.isProposalPopupOpen()) {
arg0.doit = false;
}
} catch (ParseException e) {
e.printStackTrace();
}
} });
I don't know how did you implement IControlContentAdapter, IControlContentAdapter2 in your code. Did you try this? I use that in my custom StyledText implementation. But all of them are SWT.SINGLE Text fields. I hope it may help you.

Java - GetSelectedIndexes problem

My problem is my compiler isnt recognising getSelectedIndexes. I've got all the awt and swing libraries imported and PartyList is a Jlist thats been set up and works, can anyone give me any advice, thanks
else if(e.getSource() == jButton9) // if play button is pressed
{
int []selectedIndexes = PartyList.getSelectedIndexes();
drawApp(4);
}
You probably need PartyList partyList = new PartyList();
getSelectedIndexes is a instance level method. You can't call it without instantiating the class...
You want JList's getSelectedIndices, not getSelectedIndexes.

Categories