We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello dear Processing community!
I am currently using the G4P tool for GUI creation and I can say it works great (thanks @quark), but I have just one issue with the textarea;
I want to provide the user a row selection; when the user clicks on a row with text it should mark the whole text and return the developer the line of row. But it seems like there is no way to make this, i found this article but its not possible to add this mouselistener to the textarea.
Best Regards!
textArea.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() != MouseEvent.BUTTON1) {
return;
}
if (e.getClickCount() != 2) {
return;
}
int offset = textArea.viewToModel(e.getPoint());
try {
int rowStart = Utilities.getRowStart(textArea, offset);
int rowEnd = Utilities.getRowEnd(textArea, offset);
String selectedLine = textArea.getText().substring(rowStart, rowEnd);
System.out.println(selectedLine);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
}
});
Answers
When I first read your question I wasn't sure whether it was possible or not, so I tried creating a simple Processing sketch to test out my ideas.
My ideas worked out so YES IT IS POSSIBLE and the sketch code is shown below.
BTW Don't try and use JSwing components inside Processing they don't work well because they use different event handing models.
Thank you @quark, I didn't have time lately to test your code but I will for sure let you know if I managed to get it working. Thanks again for your time and great tool!
Regards!
Hey @quark. I implemented your code, that is exactly what I was asking. Its impressive that it also works on your G4P tool.
Only thing which I think could make a issue is the text editing, it should be disabled but if you disable it the the focus is gone. Do you have a "overkill" idea? XD
Cheers!
Unfortunately there is no way round it - focus is really keyboard focus in other words i responds to keyboard events and the text is editable. If focus is lost then the text is not editable. The solution I provided above was based on detecting where the text insertion point (caret) is, which means it must be enabled and have focus.
You must remember that the GTextArea class was designed for simple multi-line text input. Since it was created many people have tried using it for a variety of tasks and some methods have been added which make them possible, but there will always be some limitations and this is one of them.
Well it serves the purpose, the problem is still solved even if you can edit the text. As I said maybe there is a "overkill" idea heheh
Kind regards!