How to disable windows beep sound on delete key press - java

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.

Related

How to differentiate between touchpad clicks

I am creating a click test for mousepad in Java. I can differentiate between left, right and middle click through:
if(evt.getButton()==3) // or 1 or 2
What I can't seem to do is to differentiate between 2 lefts.
The 2 lefts being click on 1 and click on 2 in the image above. I have tried to see if I get different values from them when I click by debugging and checking the event object but its the same. For keyboard one can differentiate between two Ctrl or 2 shifts by getting keyLocation, can one do something similar with click? Like not get where on the screen is clicked but which button was pressed.
private void formMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println(evt.getButton());
if (evt.getButton() == 3) {
//3=right
button1.setBackground(Color.GREEN);
textField1.setText("Code : Right");
} else if (evt.getButton() == 2) {
//middle
button6.setBackground(Color.GREEN);
textField1.setText("Code : Middle");
} else if (evt.getButton() == 1) {
//1=left
button5.setBackground(Color.GREEN);
textField1.setText("Code : Left");
} else {
textField1.setText("Code : " + evt.getButton());
}
}
This above is my code so far in regards with click.
I have searched a lot but couldn't find information that could help yet.
As far as I know, there is no way to do this. The trackpad will simply present itself as if mouse1 has been pressed when you click the trackpad. Keyboards have different keycodes for left/right shift, etc... I don't believe there are different keycodes for "trackpad click" and "mouse 1".
Anyway, why would you want to add functionality that only laptop users (and only certain laptop users) would be able to use. What about desktops? What about mobile?
You can you below code SwingUtilities methods
SwingUtilities.isLeftMouseButton(MouseEvent anEvent)
SwingUtilities.isRightMouseButton(MouseEvent anEvent)
SwingUtilities.isMiddleMouseButton(MouseEvent anEvent)
Like:
if(SwingUtilities.isLeftMouseButton(evt)){
// do your work
}
// same for right and middle mouse key
But if you want to check where click happed on the mouse from enter link description here
Java Swing is an old technology, it supports the traditional mouse wheel rotation events.
So i don't think its possible to get difference b/w click happening on diff location of touchpad.
From MouseEvent
There is no way to get the location of mouse click.

Java SWT - Key pressed display filter

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.

Why is KeyCode.ESCAPE being consumed by ComboBoxes and what is the work around?

In my standalone JavaFX 2 application hitting the Escape key should trigger an event that shuts the application down. But then it started not working sporadically. With further testing I realized that when any of several ComboBox components on the main display have focus, hitting Escape did nothing. But if you then click a TableView, TextBox, Button, etc. to give them the focus, it would work fine. It also stops again if focus returns to the ComboBox. Changing the triggering event to other KeyCodes seemed to fix the issue no matter which item has focus.
So focused ComboBoxes appear to be consuming KeyCode.ESCAPE events. But why? And is there a way to fix this without keeping them from obtaining focus or changing the event handler to some other key?
I think its the contained ListView popup that consumes the ESCAPE keycode because when the ListView popup is opened, hitting the escape key will close it. If you use the EventFilter mentioned by OttPrime it should work as you expect...
scene.addEventFilter(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>()
{
#Override
public void handle(KeyEvent ke)
{
if (ke.getCode() == KeyCode.ESCAPE)
{
shutDownApp(true);
}
}
});

Java popup trigger in Linux

I have an application in which you can do a right mouse button press and drag (as well as a left press and drag for different operations). However, when running this on linux, it seems that popup menus are triggered by a mousePressed and not a mouseReleased. This is resulting in every time I press the right mouse button to perform a drag, the popup menus are triggered (unlike windows, where it is mouseReleased).
Any thoughts on how to work around this?
thanks.
EDIT: Posting code
Code for popup menu
// this is called from mousePressed and mouseReleased
if (e.isPopupTrigger() && !e.isConsumed()) {
// show the popup menu
}
This code is what is called on the right mouse press/drag (this is 3rd party code, but it is open source so I can change as needed)
// this is called on all mouse events
if (buttonAction.mouseButton != 0)
{
// handle the event
}
Yes, use isPopupTrigger(), as shown here.
Addendum:
it appears isPopupTrigger is triggered on mousePressed in linux.
Yes, it's the same on Mac OS X. You have to call isPopupTrigger() from both mousePressed() and mouseReleased(). There's a related example in GraphPanel.
MouseEvent.isPopupTrigger(). Returns whether or not this mouse event is the popup menu trigger event for the platform.
edit - : You need to make the check in both mousePressed for linux, and mouseReleased for windows.
I think the correct procedure in your case should be to unify where and when to show the popup. As a drag event, if exist, follows a press event you should avoid writting logic for showing the popup in the press event (and then also write logic in the press event for showing the popup). Some users feel good navigating the popup while holding the popup button, and some other users just don't care or don't know. But in your case, you won't be able to navigate the popup menu while dragging without adding extra code.
My way would we to manage the logic to always show the popup on the release event. Entering a release event after a drag should be enough information to know that the popup shouldn't be visible. And of course, always if you can change and modify the source.

Using the Keyboard "ContextMenu" button in Java

In the application I'm working on I'd like to listen for when the keyboard's context menu (right click) button is pressed.
Just to be clear, I'm talking about the button between Alt Gr and Ctrl on the right of the spacebar. I realise it is not on all keyboards (older, mac's etc), but I know that all of the keyboards which will be using this application will have the button.
I'd like to know if there is a simple KeyEvent or any other method for knowing when it has been pressed.
Thanks,
Dave
To echo #Thijs Wouters' answer, (a) this is always a great way to figure out what key codes are associated with what keys in Java, and (b), this key code for the context menu, 525, is 20D in hexadecimal, and is defined in Java (since 1.5) as
KeyEvent.VK_CONTEXT_MENU
for ease of code reading.
You can check the key code when a key is pressed. The key code of the context menu key is 525.
You can check this for yourself:
public void keyPressed(KeyEvent e) {
System.out.println(e.getKeyCode());
}

Categories

Resources