Page 1 of 1

KeyBoard Control for deleting

Posted: Tue Oct 02, 2007 5:52 am
by 7665742
Hi:

We have looked at the example for deleting a selected line through a button control. Unfortunately, it will not work for the current setup. What we would like to do is use the "DEL" key through KeyListener to be able to delete a line from the chart. Is this possible? We have tried creating KeyListener event and it does not work. I was wondering whether anyone has any insights. Appreciate any information. Thank you.

best regards,
vasu

Posted: Tue Oct 02, 2007 10:17 am
by narcis
Hi vasu,

Probably a Java expert may know of a way to achieve this much easily. However, we found one way to add keyboard events is like in the code snippet below. Please notice that other controls (as JButton) may interfere on those events so notice the KeyListener code necessary for the buttons.

Code: Select all

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class JFrameDemo extends javax.swing.JFrame 
                        implements KeyListener
                        {
	private TChart tChart = new TChart();
	private javax.swing.JToggleButton jToggleButton1;
	private javax.swing.JToggleButton jToggleButton2;

	public JFrameDemo() {
		initComponents();
                jToggleButton1.addKeyListener(this);
                jToggleButton2.addKeyListener(this);
	}

        public void keyReleased(KeyEvent e)
        {
        }
    // 
        public void keyTyped(KeyEvent e)
        {
            tChart.getHeader().setText("KeyTyped!");
        }
    // 
        public void keyPressed(KeyEvent e)
        {
        }

//........
Hope this helps!