Java SWT - Key pressed display filter - java

In my app I added a filter to the display that handles a KeyDown event.
It works just fine when the app is running on windows, but now that I'm trying to run it on Linux it doesn't detect the keypress event.
Any ideas what can be the problem?
The code is a bit messy so I'm adding only the outline for now.
answerListener = new Listener() {
#Override
public void handleEvent(Event event) {
...
};
Display.getDefault().addFilter(SWT.KeyDown, answerListener);
The app Is a trivia game, when I press a key in the game screen, I should get 4 sec to choose an answer. So the answers button is enabled only if a key is pressed before.
There are 3 main SWT composites on the screen. A group with the answers buttons, A list with text strings, and another group at the left of the screen.
When I press on the list of strings with the mouse and then I press a key, a small text box (you can see at the picture) with my pressed key char pops up, but the answers are still disabled.
The text box appears on the screen for 4 sec and then disappears.
When I click before on any other group, the small window don’t pop up, but the answer group are again disabled.
On Windows none of those symptoms occur. The game works as it should work.

Related

How to Avoid Click Event Trigger Multiple Times in Android Java code?

i am trying to add stylus button support into an archived - unmaintained github repository named gfxtablet
Basicly it turn android tablets into a digitizer as like wacom.
It has support for drawing, hovering and even stylus pressure. This is great. Only missing piece was stylus button and i cant use it on my tablet samsung galaxy note pro 12.2 which comes with samsung s-pen.
I tried to figure out stylus button event myself by searching online for a long time ( because i am not java nor c programmer.)
Gfxtablet android app communicate with linux with c programming application name networktablet.
I read their docs and learn that i could enable stylus button with extra codes.
I could successfully enable stylus button event trigered as right mouse button by adding :
if(event.getButtonState() == MotionEvent.BUTTON_SECONDARY)
{
netClient.getQueue().add(new NetEvent(Type.TYPE_BUTTON, nx, ny, (short) 0, 2, true));
netClient.getQueue().add(new NetEvent(Type.TYPE_BUTTON, nx, ny, (short)0, 2, false));;
}
inside
#Override
public boolean onGenericMotionEvent(MotionEvent event) {
...
My edit is this :
Original file is here ,line 110
i add code above after switch statement.
it works but the problem is , code fired multiple events and as a result it behave as like i right click mouse button around 5-10 times in a second when i click stylus s-pen button.
Main objective i am trying to achieve, is , i wished to use samsung s-pen 's button for right mouse click and use it on Krita painting app's popup palette.
As like you see pictures , button event trigger multiple times in terminal and in krita popup palette open and close many times in a second.
I need help to figure this out. Thanks

How to remove or disable the "Tabulator Selector" in Java on Windows OS?

So my Java GUI always shows the current selected JButton by displaying a white rectangle around it. By hitting Tab or Shift + Tab the selection goes to the next/previous element.
Here is my custom decoration Panel(as an example). Is there a possiblity to hide this white frame?
By the way it has no function, if I press enter key nothing happens...

How can I simulate a backspace without using keyevent for my calculator app?

I am working on a delete button, and I created the following:
void onDelete() {
if (!getText().equals(strResult) && !isError) {
mDisplay.dispatchKeyEvent(new KeyEvent(0, 67));
strResult = "";
} else {
clear(false);
}
}
So, when I press the buttons 456 on the calculator app, press delete, 45 remains on the small screen on top ( I don't really know what to call it, just the field that shows what your input is, just like a normal calculator has), exactly how it is supposed to be. However, this will only work if I 'select' the small screen on top. So, when I start the app, click the buttons 456, then press the del button, nothing happens, since I have to 'touch' the small screen on top first to let the cursor 'take place'. I want, however, that it is not necessary to select the calculator screen before using the delete button.
The code I used is based on this code:

How to navigate through Vaadin grid and select an item using keyboard?

I'd like to know if it's possible to navigate through Vaadin grid or treegrid and select an item using only keyboard arrow keys? From what i've seen while testing the components, the default behavior seems to be either to move only to one specific cell in grid or to a specific row in treegrid. Selection can be achieved if the user presses spacebar.
I've tried to add a shortcutListener to grid but it doesn't seem to work with arrow keys. And the grid scrollbar doesn't move with the selected item.
grid.addShortcutListener(new ShortcutListener("Down", KeyCode.ARROW_DOWN, null) {
#Override
public void handleAction(Object sender, Object target) {
//..//
selectedItem = dataSource.get(currentSelectedItemIndex);
grid.select(selectedItem);
grid.scrollTo(currentSelectedItemIndex); // this doesn't seem to do anything??
//..//
}
});
I guess my problem is that i don't know how to acquire event that moves selection to other cell/row.
Here's an image to represent the problem which i'm facing. The item that has only blue border was selected using arrow keys. I'd like to select an item automatically when user presses arrow keys (Down or Up) without the spacebar.
Image taken from here: https://demo.vaadin.com/sampler/#ui/grids-and-trees/grid/features
Edit1:
I'm using latest version of Vaadin - 8.1.6.
Edit2:
I tried to add couple of listeners to see if i could at least register the movement to the next/previous cell by using arrow up/down but without any luck.
Here's a list of listeners i've tried:
addSelectionListener - only registers selection after spacebar press
or mouse click. Not quite what i'm looking for.
addItemClickListener - only registers selection from mouse click.
addShortcutListener - registers pressed key but it doesn't work with arrows.
Is there any listener that could potentially help me with this issue?
The Grid component has basic keyboard navigation. If you need advanced options, like you have mentioned, for keyboard navigation, I would warmly recommend to test this add-on:
https://vaadin.com/directory/component/gridfastnavigation-add-on

How to disable windows beep sound on delete key press

I have a java swing application that beeps everytime I delete a row in a jtable.
Anyone have any ideas how I can prevent this from happening or at least what is causing this?
From here: https://www.java.net/node/687490
On Windows, pressing the Alt key moves the keyboard focus to the
window menu in the top left corner. This focus is invisible, and it
even does not send a "focus lost" event. But if you press and release
Alt and then press the up or down arrow, the window menu will show up.
Luckily, it's possible to prevent this functionality of the Alt key:
addKeyListener( new KeyAdapter() {
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed code=" + e.getKeyCode());
e.consume();
} } );
e.consume( ) prevents the event to be processed by usual rules. This
prevents the Alt key from moving the focus to the window menu, and
further alphanumeric keys continue to function as usual. You may want
to check the event code and consume only Alt keys, if something else
stops working.

Categories

Resources