Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How do I prevent a multi-line text field from "stealing" tab-key presses? on Swt Table( I mean: I'd like to use TAB to cycle between the elements of a window, but when I enter the multiline text, TAB becomes a "normal" key, and simply inserts tabulators into the text I'm typin)
icon13.gif  How do I prevent a multi-line text field from "stealing" tab-key presses? on Swt Table [message #1749210] Sat, 03 December 2016 06:40
surekha somisetty is currently offline surekha somisettyFriend
Messages: 18
Registered: April 2016
Junior Member
We implement Swt Table Editor Example we need swt table editor text flexible with line by line

I'd like to use TAB to cycle between the elements of a window, but when I enter the multiline text, TAB becomes a "normal" key, and simply inserts tabulators into the text I'm typing.

How do I handle this? Should I write some custom listener, or can I change the behaviour of the component by using an SWT constant?

My editor example is :

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

public class TableEditorExample {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
for (int i = 0; i < 3; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
for (int i = 0; i < 3; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] { "" + i, "" + i, "" + i });
final TableEditor editor = new TableEditor(table);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
table.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
Rectangle clientArea = table.getClientArea();
Point pt = new Point(event.x, event.y);
int index = table.getTopIndex();
while (index < table.getItemCount()) {
boolean visible = false;
final TableItem item = table.getItem(index);
for (int i = 0; i < table.getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
final int column = i;
final Text text = new Text(table, SWT.NONE);
Listener textListener = new Listener() {
public void handleEvent(final Event e) {
switch (e.type) {
case SWT.FocusOut:
item.setText(column, text.getText());
case SWT.Traverse:
switch (e.detail) {
.setText(column, text
e.doit = false;
text.addListener(SWT.FocusOut, textListener);
text.addListener(SWT.Traverse, textListener);
editor.setEditor(text, item, i);
if (!visible && rect.intersects(clientArea)) {
visible = true;
if (!visible)
while (!shell.isDisposed()) {
if (!display.readAndDispatch())

But I need below flexibility on swt Table is it possible
This Example is in Swing JFace JTable, I need Swt Table

import javax.swing.*;
import java.awt.BorderLayout;

public class TextAreaRendererTest extends JFrame {
// The table has 10 rows and 3 columns
private final JTable table = new JTable(10, 3);

public TextAreaRendererTest() {
// We use our cell renderer for the third column
new TextAreaRenderer());
// We hard-code the height of rows 0 and 5 to be 100
table.setRowHeight(0, 100);
table.setRowHeight(5, 100);
// We put the table into a scrollpane and into a frame
getContentPane().add(new JScrollPane(table));
// We then set a few of the cells to our long example text
String test = "The lazy dog jumped over the quick brown fox";
table.getModel().setValueAt(test, 0, 0);
table.getModel().setValueAt(test, 0, 1);
table.getModel().setValueAt(test, 0, 2);
table.getModel().setValueAt(test, 4, 0);
table.getModel().setValueAt(test, 4, 1);
table.getModel().setValueAt(test, 4, 2);

public static void main(String[] args) {
TextAreaRendererTest test = new TextAreaRendererTest();
test.setSize(600, 600);

Help me Any One

Previous Topic:Which Eclipse plugin contains org.eclipse.swt ?
Next Topic:SWT on Neon not rendering some window controls fully with GTK3
Goto Forum:

Current Time: Sat Apr 17 15:36:23 GMT 2021

Powered by FUDForum. Page generated in 0.01294 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top