Bug 6204 - KeyListener on table does not work.
Summary: KeyListener on table does not work.
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Veronika Irvine CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-11-21 17:40 EST by Eduardo Pereira CLA
Modified: 2001-12-03 17:26 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eduardo Pereira CLA 2001-11-21 17:40:21 EST
Build 20011120 - Linux Motif.

The following example will open a Shell with one menu option. Ctrol+F6 will 
open a dialog with a table.

** A key listener is added to the table but the keypressed and keyreleased 
methods do not get called.

Once "**" is fixed. Press Ctrol+F6 and hold control pressed.
Press F6 again. The selection shoul be set to the next element and so on.
When Ctrol is released, the dialog should close and the selection printed in 
the console.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import org.eclipse.swt.widgets.*; 
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.custom.*;

public class AltTabTest {
	
	static int count = 0;
	
	public static void main(String[] args) {
 
		final Shell s = new Shell();
		final Display d = s.getDisplay();
		s.setBounds(100, 100, 600, 600);
					
		s.setMenuBar(new Menu(s,SWT.BAR));
		s.getMenuBar().setVisible(true);
		MenuItem mii = new MenuItem(s.getMenuBar(),SWT.CASCADE);
		mii.setText("PRESS CTRL+F6");
		
		Menu m = new Menu(s.getMenuBar());
		mii.setMenu(m);
		MenuItem mi = new MenuItem(m,SWT.NONE);
		mi.setText("Open Dialog with Table");
		mi.setAccelerator(SWT.CONTROL|SWT.F6);
		
		mi.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				final Shell s1 = new Shell
(s,SWT.APPLICATION_MODAL);
				s1.setLayout(new FillLayout());
				final Table t = new Table(s1,SWT.SINGLE | 
SWT.FULL_SELECTION);
				t.setHeaderVisible(true);
				t.setLinesVisible(true);
				
				TableColumn tc = new TableColumn(t,SWT.NONE);
				tc.setText("HEADER");
				tc.setResizable(false);
				
				TableItem i = new TableItem(t,SWT.NONE);
				i.setText("AAAAAAAAAAA");
				i = new TableItem(t,SWT.NONE);
				i.setText("BBBBBBBBBBBBB");
				i = new TableItem(t,SWT.NONE);
				i.setText("CCCCCCCCCCC");
							
				tc.pack();
				t.pack();
				s1.pack();
				tc.setWidth(t.getClientArea().width);
				
				t.addKeyListener(new KeyListener(){
					public void keyPressed(KeyEvent e){
						System.out.println("key 
pressed: " + e.keyCode);
						if(e.keyCode == SWT.F6) {
							t.setSelection
((t.getSelectionIndex() + 1) % t.getItemCount());
						}
					}
					public void keyReleased(KeyEvent e) {
						System.out.println("key 
released: " + e.keyCode);
						if(e.keyCode == SWT.CONTROL) {
							System.out.println
(t.getSelection()[0].getText());
							s1.close();
						}
					}
				});
				s1.setLocation(150,150);
				s1.open();
				t.setSelection(2);
				t.setFocus();
				while (!s1.isDisposed()) {
					if (!d.readAndDispatch())
						d.sleep();
				}
			}
			public void widgetDefaultSelected(SelectionEvent e){
			}
			
		});
		
		s.open();
			
		while (!s.isDisposed()) {
			if (!d.readAndDispatch())
				d.sleep();
		}
	}
	
}
Comment 1 Grant Gayed CLA 2001-12-03 17:26:55 EST
Fixed by removing the focus proxy that the Table was using to get keyboard 
events.