Skip to main content

AutoComplete does not work after entering JComboBox in JTable by F2

4 replies [Last post]
tiler
Offline
Joined: 2007-05-18

SwingX-AutoComplete for a JComboBox in a JTable is working fine after entering the combo box by a mouse click -> the text (if available) is marked initially and each character key is processed as required.
But if the edit mode is entered by VK_F2 the behaviour is completely different. The text is not marked and each character key is treated as if it is the 1st character - it matches always only to the 1st character of the available choices.
In other words: the auto complete function does not work if the combo box is entered by VK_F2.
Does anybody have an idea how to solve this issue?
My java version: 1.4.1_02-b06; My SwingX version: 2007_05_13

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tiler
Offline
Joined: 2007-05-18

Steps for wrong auto-complete:
- start the application (or press ESCAPE)
- select one of the cells by arrow keys
- press F2 to switch the cell into edit mode
- try to use character keys for auto-complete -> it does not work properly

Steps for sufficient auto-complete:
- start the application (or press ESCAPE)
- select one of the cells by a mouse click -> the cell is implicitly switched into edit mode
- try to use character keys for auto-complete -> it is working properly

Demo application:

import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.awt.*;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor;

public class AutoCompleteTable extends JTable {

public AutoCompleteTable() {
this.setModel(new TableTeilnehmerModel(this));
((TableColumn) this.getColumn(COLNAME_PERSON)).setCellEditor(new ComboBoxCellEditor(jComboPerson));
AutoCompleteDecorator.decorate(jComboPerson);
}

// Spaltenüberschriften
final static String COLNAME_PERSON = "Person";

public void setTeilnehmerCollection(Vector teilnehmer) {
m_Teilnehmer = teilnehmer;
}
public Vector getTeilnehmerCollection() {
return m_Teilnehmer;
}
Vector m_Teilnehmer = new Vector();
String[] combonames= {"Beate", "Claudia", "Fjodor", "Fred", "Friedrich", "Fritz", "Frodo", "Hermann", "Willi"};
JComboBox jComboPerson = new JComboBox(combonames);

public void setEditable(boolean editable) {
jComboPerson.setEditable(editable);
}

private class TableTeilnehmerModel extends AbstractTableModel {
public TableTeilnehmerModel(AutoCompleteTable table) {
m_Table = table;
}
private AutoCompleteTable m_Table;

public int getColumnCount() { return 1; }
public int getRowCount() {
if (m_Teilnehmer == null)
return 0;
return m_Teilnehmer.size();
}
public Object getValueAt (int row, int col) {
return m_Teilnehmer.toArray()[row];
}
public String getColumnName(int column) {
switch (column) {
case 0: return COLNAME_PERSON;
}
return "";
}
public boolean isCellEditable(int row, int col) { return true; }
public void setValueAt(Object value, int row, int col) {
if (m_Teilnehmer != null && row < m_Teilnehmer.size()) {
m_Teilnehmer.setElementAt(value,row);
}
}

};

public Vector initTeilnehmer() {
Vector teilnehmer = new Vector();
teilnehmer.add("Beate");
teilnehmer.add("Claudia");
teilnehmer.add("Hermann");
teilnehmer.add("Willi");
return teilnehmer;
}

public static void main(String arg[])
{
JFrame f = new JFrame("AutoCompleteTable");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(240,280);
Container cp= f.getContentPane();
cp.setLayout(null);

AutoCompleteTable act = new AutoCompleteTable();
act.setTeilnehmerCollection(act.initTeilnehmer());
act.setBounds(20,20,190,200);
act.setEditable(true);
cp.add(act);

f.setVisible(true);
}

}

kschaefe
Offline
Joined: 2006-06-08

Can you please post a small, runnable demo of this problem? And the directions to exibit the behavior?

Karl

tiler
Offline
Joined: 2007-05-18

Steps for wrong auto-complete:
- start the application (or press ESCAPE)
- select one of the cells by arrow keys
- press F2 to switch the cell into edit mode
- try to use character keys for auto-complete -> it does not work properly

Steps for sufficient auto-complete:
- start the application (or press ESCAPE)
- select one of the cells by a mouse click -> the cell is implicitly switched into edit mode
- try to use character keys for auto-complete -> it is working properly

Demo application:

import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.awt.*;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor;

public class AutoCompleteTable extends JTable {

public AutoCompleteTable() {
this.setModel(new TableTeilnehmerModel(this));
((TableColumn) this.getColumn(COLNAME_PERSON)).setCellEditor(new ComboBoxCellEditor(jComboPerson));
AutoCompleteDecorator.decorate(jComboPerson);
}

// Spaltenüberschriften
final static String COLNAME_PERSON = "Person";

public void setTeilnehmerCollection(Vector teilnehmer) {
m_Teilnehmer = teilnehmer;
}
public Vector getTeilnehmerCollection() {
return m_Teilnehmer;
}
Vector m_Teilnehmer = new Vector();
String[] combonames= {"Beate", "Claudia", "Fjodor", "Fred", "Friedrich", "Fritz", "Frodo", "Hermann", "Willi"};
JComboBox jComboPerson = new JComboBox(combonames);

public void setEditable(boolean editable) {
jComboPerson.setEditable(editable);
}

private class TableTeilnehmerModel extends AbstractTableModel {
public TableTeilnehmerModel(AutoCompleteTable table) {
m_Table = table;
}
private AutoCompleteTable m_Table;

public int getColumnCount() { return 1; }
public int getRowCount() {
if (m_Teilnehmer == null)
return 0;
return m_Teilnehmer.size();
}
public Object getValueAt (int row, int col) {
return m_Teilnehmer.toArray()[row];
}
public String getColumnName(int column) {
switch (column) {
case 0: return COLNAME_PERSON;
}
return "";
}
public boolean isCellEditable(int row, int col) { return true; }
public void setValueAt(Object value, int row, int col) {
if (m_Teilnehmer != null && row < m_Teilnehmer.size()) {
m_Teilnehmer.setElementAt(value,row);
}
}

};

public Vector initTeilnehmer() {
Vector teilnehmer = new Vector();
teilnehmer.add("Beate");
teilnehmer.add("Claudia");
teilnehmer.add("Hermann");
teilnehmer.add("Willi");
return teilnehmer;
}

public static void main(String arg[])
{
JFrame f = new JFrame("AutoCompleteTable");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(240,280);
Container cp= f.getContentPane();
cp.setLayout(null);

AutoCompleteTable act = new AutoCompleteTable();
act.setTeilnehmerCollection(act.initTeilnehmer());
act.setBounds(20,20,190,200);
act.setEditable(true);
cp.add(act);

f.setVisible(true);
}

}

Thomas Bierhance

Thanks a lot for posting the example. I'll have a look at it.

Thomas

jdnc-interest@javadesktop.org wrote:
> Steps for wrong auto-complete:
> - start the application (or press ESCAPE)
> - select one of the cells by arrow keys
> - press F2 to switch the cell into edit mode
> - try to use character keys for auto-complete -> it does not work properly
>
> Steps for sufficient auto-complete:
> - start the application (or press ESCAPE)
> - select one of the cells by a mouse click -> the cell is implicitly switched into edit mode
> - try to use character keys for auto-complete -> it is working properly
>
> Demo application:
>
> import javax.swing.*;
> import javax.swing.table.*;
> import java.util.*;
> import java.awt.*;
> import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
> import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor;
>
> public class AutoCompleteTable extends JTable {
>
> public AutoCompleteTable() {
> this.setModel(new TableTeilnehmerModel(this));
> ((TableColumn) this.getColumn(COLNAME_PERSON)).setCellEditor(new ComboBoxCellEditor(jComboPerson));
> AutoCompleteDecorator.decorate(jComboPerson);
> }
>
> // Spaltenüberschriften
> final static String COLNAME_PERSON = "Person";
>
> public void setTeilnehmerCollection(Vector teilnehmer) {
> m_Teilnehmer = teilnehmer;
> }
> public Vector getTeilnehmerCollection() {
> return m_Teilnehmer;
> }
> Vector m_Teilnehmer = new Vector();
> String[] combonames= {"Beate", "Claudia", "Fjodor", "Fred", "Friedrich", "Fritz", "Frodo", "Hermann", "Willi"};
> JComboBox jComboPerson = new JComboBox(combonames);
>
> public void setEditable(boolean editable) {
> jComboPerson.setEditable(editable);
> }
>
> private class TableTeilnehmerModel extends AbstractTableModel {
> public TableTeilnehmerModel(AutoCompleteTable table) {
> m_Table = table;
> }
> private AutoCompleteTable m_Table;
>
> public int getColumnCount() { return 1; }
> public int getRowCount() {
> if (m_Teilnehmer == null)
> return 0;
> return m_Teilnehmer.size();
> }
> public Object getValueAt (int row, int col) {
> return m_Teilnehmer.toArray()[row];
> }
> public String getColumnName(int column) {
> switch (column) {
> case 0: return COLNAME_PERSON;
> }
> return "";
> }
> public boolean isCellEditable(int row, int col) { return true; }
> public void setValueAt(Object value, int row, int col) {
> if (m_Teilnehmer != null && row < m_Teilnehmer.size()) {
> m_Teilnehmer.setElementAt(value,row);
> }
> }
>
> };
>
> public Vector initTeilnehmer() {
> Vector teilnehmer = new Vector();
> teilnehmer.add("Beate");
> teilnehmer.add("Claudia");
> teilnehmer.add("Hermann");
> teilnehmer.add("Willi");
> return teilnehmer;
> }
>
> public static void main(String arg[])
> {
> JFrame f = new JFrame("AutoCompleteTable");
> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> f.setSize(240,280);
> Container cp= f.getContentPane();
> cp.setLayout(null);
>
> AutoCompleteTable act = new AutoCompleteTable();
> act.setTeilnehmerCollection(act.initTeilnehmer());
> act.setBounds(20,20,190,200);
> act.setEditable(true);
> cp.add(act);
>
> f.setVisible(true);
> }
>
> }
> [Message sent by forum member 'tiler' (tiler)]
>
> http://forums.java.net/jive/thread.jspa?messageID=218034
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net