Press « Event « Java Swing Q&A





1. How to stop repeated keyPressed() / keyReleased() events in Swing    stackoverflow.com

So the problem that I am having appears to be a bug that occurs only on Linux. I'm trying to have my swing app record when a key is pressed down, ...

2. Java/AWT/Swing: how to distinguish the pressed enter or return key    stackoverflow.com

It looks like native applications behave differently if the user presses the Return key (right to the characters) or the Enter key (number key pad) - one time a new line ...

3. KeyPressed event    stackoverflow.com

I'm trying to learn something about GUI, using NetBeans6.8, starting with the GUI section in The java tutorial. There is a simple exercise for a Celsius-Fahrenheit converter. I want that to have ...

4. keyPressed Listener produces strange behaviour    stackoverflow.com

I have a series of Text- and Comboboxes along a jTable. I use the input from the boxes to filter the results of a JPQL-query, which are displayed on the jTable. ...

5. Java KeyListener keyPressed method fires too fast    stackoverflow.com

If you use the java KeyListener class you know that if you hold down a key keyPressed will fire one KeyEvent, and then about half a second later will fire the ...

6. Why won't the keyPressed method be called?    stackoverflow.com

I'm making a fighting game in Java for a project and trying to get a picture to move and be repainted across the panel reacting to the keyboard (keyEvents). I'm ...

7. keyReleases are simulating keyPresses in Linux (java Swing GUI)    stackoverflow.com

I have a kiosk GUI application I'm working on and it requires me to block users from being able to Alt-Tab out of the fullscreen window. I posted a question about ...

8. Java Swing - Pressed key gets not released (sometimes)    stackoverflow.com

For a game, I use a KeyListener to know when a key is pressed down.

public synchronized void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
    ...

9. Java MouseEvent, check if pressed down    stackoverflow.com

I have a class that implements MouseListener (JPanel). When I click on the panel something happens. What I want is some kind of while-loop that loops as long as left mousebutton ...





10. How to hide the JWindow when I press Enter key?    stackoverflow.com

I have a frame and a JWindow. In my frame I have a textfield, whenever I type something to the field, the window will appear with list of suggestions below the ...

11. Any suggestions on why the triangle is not rotating when I press a key?    stackoverflow.com

I am looking for an answer to why the triangle is not rotating when I press a key.

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.GeneralPath;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Beta extends JPanel implements ...

12. How to ignore the key press event in Swing?    stackoverflow.com

I want to make the text field only accept numeric and backspace button from the user. I have added the function that use to check the keycode from the user, but I ...

13. Pressing a key from the code    coderanch.com

Hi Prakshi, Have a look at the helper class I wrote below. It might be just what you want. class FakeEvent { public static void fakeActionPerformed( Component c ) { ActionEvent ae = new ActionEvent( c, ActionEvent.ACTION_PERFORMED, "" ); fakeExecute( ae ); } public static void fakeKeyPressed( Component c, int keyCode ) { GregorianCalendar gc = new GregorianCalendar(); KeyEvent ke = ...

14. getting action from field without pressing enter    coderanch.com

I have some JTextFields and I want to be able to capture user action without relying on the user to press enter. most people I see using my program fill in the fields and move on to the next one without pressing enter at each one. And I don't want to put in a button. Can i get the action to ...

15. to identify keypressed event in java    coderanch.com





17. Difference between Keypressed and KeyTyped    coderanch.com

Hi all, I have searched about difference between KeyPressed and KeyTyped Events but still I'm not clear about that . One thing I have found is Keypressed is triggered first than KeyTyped . Please clarify me when these are triggered exactly . Which is appropriate to use for which purpose ? Thanks in advance

18. keyPressed not working    coderanch.com

Hi, Basically this is a part of my assignment. A space ship simulator. All was working then I had to implement arrow keys listeners. The problem is that with the debug the code is not being executed and helt at the addKeyListener(new KeyAdapter(). Here Below please fine part of my code that help you understand such problem. Begining with the MAIN ...

19. A good keyListener for mulitple key's pressed    coderanch.com

> how would I go about just getting a response for only the control key than? > Say if i just press the control key i want to output "hello world". I've never written anything just for the control key (such a bad idea in a program), but, just for the exercise, a minute or so of tinkering and this seems ...

20. one key press    coderanch.com

import javax.swing.*; import java.awt.*; import java.awt.event.*; class Testing { public void buildGUI() { JComboBox cbo = new JComboBox(new String[]{"London","Madrid","New York","Rome","Sydney","Washington"}); cbo.setEditable(true); final JButton btn = new JButton("OK"); JPanel p = new JPanel(); p.add(cbo); p.add(btn); JFrame f = new JFrame(); f.getContentPane().add(p); f.setSize(300,200); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); btn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ System.out.println("OK"); } }); Toolkit.getDefaultToolkit().addAWTEventListener( new AWTEventListener(){ public void eventDispatched(AWTEvent e) { ...

22. Multiple Key Press    coderanch.com

Trying to figure out the animation framework in Java and i managed to get a box to move around a JFrame. I can move up down left and right using the arrow keys. How can i tell the box to move diagonally up without using a new key. So how do i know if the user pressed the up and right ...

23. KeyPressed event in canvas using j2me    coderanch.com

Dear All, I have two java classes here. ------------------------------------------------------------------------------------ Services.java public class Services extends MIDlet { Display display; private TCanvas canvas = new TCanvas(this); public Services() { } public void startApp() { Display.getDisplay(this).setCurrent(canvas); } public void pauseApp() { } public void destroyApp(boolean unconditional) { notifyDestroyed(); } } ----------------------------------------------------------------------------------- TCanvas.java public class TCanvas extends Canvas implements CommandListener { private Image headerImage = ...

26. long key press    coderanch.com

27. Listening for keyPressed Event    coderanch.com

I wrote a program that moves a gun left and right across a JPanel in response to the user pressing the left and right arrow keys. The program also fires bullets at falling objects by pressing the spacebar. If I am gliding right or left with the arrow keys and then press the spacebar to fire, the arrow key stops responding. ...

28. Robot keyPress issue    coderanch.com

29. Not getting key pressed event.    coderanch.com

My class is very simple: package test; import java.awt.Font; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; public class SSCEPanel extends javax.swing.JPanel implements KeyListener { public SSCEPanel() { initComponents(); } private void initComponents() { addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { formKeyPressed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); } private void formKeyPressed(java.awt.event.KeyEvent ...

30. Help - Swing Timers, Two Keypresses    java-forums.org

I am making a 2 player game that needs two objects to move around. In a KeyEvent, it detects when I move Player 1 Up and Down (jLabel7) using the Up key and the Down key. In the same KeyEvent, it detects when I can move Player 2 Up and Down (jLabel6) using the W key (up) and the S key ...

31. Robot class,Keypress    java-forums.org

we are presently working on a Java application using robot class. And we have used "keypress" method to send key to active window of application. Its working fine on text-editor,browsers ,windows explorer,flash games,etc but when we tried it on application like Turbo C,NFS(game),etc it fails to send keys to such a non-frame application. what might be the reason and can you ...

32. How to correctly identify "alt shift +" keypress?    java-forums.org

This is actually a specific instance of a general problem that is driving me batty. Here are the specifics. In programs such as, say, browsers, it's common to assign the key combo "alt -" to reduce font size, and "alt +" (which is to say, "shift alt +" on US keyboards) to increase font size. I want to make it easy ...