How to add KeyListener on JTable

Hello everybody,
I have a Jtable and i want to use the up and down key on the keyboard. I don't find the method how allow me to do that. I try "addKeyListener" but no result.
Please help me !!!!
Thanks .
PS : excuse for my bad english.

i try to be clear :o)))
I have a text on a JtextPane and i have a table (include in a JSrcollPane)
when i clicked in the text, il select the good entry in the table, when a do the same (by clicking addmouselistener) on the Jtable i hightlight un part of text. OK !!! for this its good !!!
The second thing i must doing :
when i use the up and down key on the Jtextpane its good i have the comportment describe before. But when i use the up and key doxn in my table its doesnt work !!!
the focus is also in my jtextpane, this event is not catch by my Jtable but by JtextPane

Similar Messages

  • How to add data into JTable

    How can I add data into JTable, for instance ("Mike", "Gooler", 21).

    How can I add data into JTable, for instance ("Mike",
    "Gooler", 21).You will have very good results if you segregate out the table model as a seperate user class and provide a method to add a row there. In fact, if you use the table to reflect a database table you can add the row inplace using the existing cursor. I believe it's TableExample2 in the jdk\demo\jfc\TableExamples that has a very good example of this.
    Walt

  • How can I add KeyListener to JTable editor

    Hi, I want to know how can I add a KeyListener to a JTable editor?
    I want to capture the event when any of the cell in the jtable has a key typed.

    If your goal is to check the entered value, it's more elegant to do this in overriding
    DefaultCellEditor#stopCellEditing and return false when the value is not correct.
    Example from a DateEditor:
            @Override public boolean stopCellEditing() {
                String value = ((JTextField)getComponent()).getText();
                if(!value.equals("")) {
                    try {
                        formatterE.parse(value);
                    } catch (ParseException e) {
                        ((JComponent)getComponent()).setBorder(new LineBorder(Color.red));
                        return false;
                return super.stopCellEditing();
            }

  • How to add JTextArea in JTable

    Hi..
    I want to add JTextArea in my table in one of the column of JTable. I have already written a code which implements TablecellEditor and TableCellRenderer. I have already succeeded to set textarea in one cell for multiple line but when i go to another cell my previous value disappears. Can anybody tell me the solution.

    I think the reason that this is happening, is that you have to override the setValue method in TableModel, inorder for the value to be displayed correctly.
    Another thing.
    I too am trying to implement a textarea as one of the cells in a col.
    But the problem is that when I create my celleditor extends TextArea and implements TableCellEditor, and compile it says that all eventLsiteners are already implemented .
    And if I just extend the AbstractCellEditor, and return it in the method getCellEditor, it says incompatible types.
    Can you tell me how to implement a CustomCellEditor
    Thanks,

  • How to add events in JTable fields

    Hello friends i m working with file transfer client server project in my college.In my client part i have used JTable with AbstractTableModel.
    In my JTable it list the current directory files and directories under current directory .
    now how can i add events to the the directories that it shows on JTable so that when i click on directory it displays files under that selected directory.
    can anyone help me in that.
    I will send you my code for that project if anyone can help me.
    please help me to do that

    You can handle row selections with selection listener but if you want to handle double clicks you can use something similar to this:
    table.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    int column = table.columnAtPoint(e.getPoint());
    int row = table.rowAtPoint(e.getPoint());
    Object cellValue = table.getValueAt(row, column); 
    // Insert files below clicked row
    });Please, be more patient in the future -you would probably get an answer if you just posted to any of these two forums.

  • How to add actionlistener to JTable?

    I have created a JTable. and I would like to while I double-click any row of JTable, I go to next frame. How can I add actionlistener to each row?

    Here's an example:
    TableF modeltable = new TableF();
    JTable FuncsTable = new JTable(modeltable);
    FuncsTable.addMouseListener(mlTable);
    MouseListener mlTable = new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    if ( e.getClickCount() == 2 ) {
    System.out.println( FuncsTable.getSelectedRow());
    your code

  • How to add  ComboBox in Jtable Header

    Hello everyone,
    I want to add a Combox box in JTable Header .Basically it works as central access to whole table e.g. by selecting delete row in combo box then it should delete the current selected row.If somebody has any idea please share it.
    Thanks in advance.

    The individual headers are not Swing components and therefore do not respond to mouse events in the same way as Swing components. Why don't you just have a popup menu that is positioned over the currently selected row? If you want to apply an action to all selected rows then have a set of buttons placed above the table header.

  • How to add Chekbox in Jtable?

    I am working on Swing application and my requirement is add new column that dispay the checkboxes, so user have the access to check/uncheck row for further process.
    In application 3 tabbedpanes are there & in the 3rd tabbedpane table data is displaying.
    //Code snippet
    public class AIProductPropertiesUI
    private productsTablemodel productmodel = null;
    private String [] pNames = {"select","type","name","revision","marketing","relationship"};
    public JPanel getMiscPanel()
    productmodel= new productsTablemodel();
    table = new JTable(productmodel);
    protected class productsTablemodel extends AbstractTableModel
    Vector productDetails ;
    productsTablemodel()
    productDetails = model.getProductDetails();
    headerNames = model.getLabelNameMapping();
    public Object getValueAt(int rowIndex, int columnIndex)
    if (productDetails.size()>0)
    Hashtable ht = (Hashtable) productDetails.get(rowIndex);
    //ht contains the list of values for all the column as in pNames[].
    // dynamic value for Select column is ""(blank string)
    String str = "" ;
    if(ht.containsKey(pNames[columnIndex]))
    str = (String) ht.get(pNames[columnIndex]);
    return str;
    }else{
    return null;
    I tried following ways-
    1)if(column==0)
    return new JCheckBox("str",true);
    here output is dispaying complete details of Checkbox
    /* output for checkbox cell is --- javax.swing.JCheckBox[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,
    border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@b1b4c3,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,
    disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=false,paintFocus=true,
    pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=str]*/
    2)overiding public Class getColumnClass(int column)
    if(column==0)
    return Class.forName("java.lang.Boolean");
    till this point its working fine... but in above code method public Object getValueAt(int rowIndex, int columnIndex)
    I am checking if(Column==0)
    return Class.forName("java.lang.Boolean");
    here it is throwing ClassCastException.. java.lang.Class cannot be cast to java.lang.Boolean
    Please provide me solution aas soon as possible...coz from past 2 days i m stucking on this and due to this not able to move ahead on my application development.
    Thanks in Advance
    Sharad

    more time researching instead of cross-posting would be better for you
    [http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=018027]

  • HOW TO ADD COLORS TO JTABLE ROWS??

    I want to change the colors of alternate rows in my JTable. I am doing so using CellRenderer, but then I am not able to view the selected rows.
    tell me how can I change the row color as well as a selected row should be identifiable from others, as ordinary JTable.
    thanks

    Hi,
    try this:
    define your own DefaultTableCellRenderer like this:
    class MyRenderer extends DefaultTableCellRenderer     {
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column){
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (isSelected) setBackground( Color.anyColor );               
    return this;
    Hope it helps!
    Regards, Paul

  • How to add unicode in jtables?

    Well basically the name of the topic is the question. If you could show it directly in the code below that would be really great. Thanks.
    import javax.swing.*;
    public class TestUnicode extends JFrame {
         JTable table;
         String[] names = {"Name"};
         String[][] data = {{"GBP: \00A3"}, {"EUR: \20AC"}};
         public TestUnicode() {
              setTable();
              getContentPane().add(new JScrollPane(table));
              setSize(300, 300);
              setLocationRelativeTo(null);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
         private void setTable() {
              table = new JTable(data, names);
         public static void main(String args[]) {
              new TestUnicode();
    }

    Add a lowercase "u" (for unicode) after your slashes: \u20AC.

  • How to add image in jtable header using 'Default table model'

    Hi,
    I created a table using "DefaultTableModel".
    im able to add images in table cells but not in 'table header'.
    i added inages in table by overriding "getColumnClass" of the DefaultTableModel.
    But what to do for headers?
    please help.
    Thanks in advance.

    The 'Java 5 tutorial' is really an outstanding oneI should note the the current tutorial on the Sun website has bee updated for Java 6. It contains updates to reflect the changes made in JDK6. Once of the changes is that sorting of tables is now supported directly which is why I needed to give you the link to the old tutorial.
    http://java.sun.com/docs/books/tutorial/uiswing/TOC.html

  • SAMPLE CODE  + HOW ADD JCOMBOBOX IN JTABLE

    HI,
    ALL OF U
    PLZ SUGGEST ME HOW TO ADD COMBOBOX IN JTABLE.
    AND ALSO TELL HOW WE CAN ADD ITEMS IN COMBOBOX AT RUN TIME.
    PLZ SUGGEST ME.
    THANX IN ADVANCE.
    BYE

    Hi if you google you find a lot
    http://www.google.be/search?q=JTable+combobox&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:nl:official&client=firefox-a
    and
    http://www.google.be/search?q=JTable+combobox+example&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:nl:official&client=firefox-a
    Satanduvel

  • Add JTree in JTable

    How to add JTree in JTable?
    Please tell me?

    you need to use a TableCellRenderer, that implements your JTree, for cell renderers see http://java.sun.com/docs/books/tutorial/uiswing/components/table.html and http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer
    thomas

  • How to add name from text file to jtable?

    hello all,
    how to add name (string) from the notepad file(.txt) into jTable rows.
    I am not able to add it.
    try {
                 FileInputStream fis = new FileInputStream("Devices/Devices_Lst.txt");
                 BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                 String line = null;
                 Vector data = new Vector();
                 line = br.readLine();
                 while ( (line = br.readLine()) != null)
                    int rowCount1 = nmsTable.getRowCount();
                    for(int i=0;i<rowCount1;i++)      
                        myTableInit();  // it initialize the table
                       /* nmsTable.setValueAt(i+1,i,0);
                        Table.setValueAt(line,i,1);
                        Table.setValueAt(" ",i,2);
                        Table.setValueAt(" ",i,3);
                        Table.setValueAt(" ",i,4);
                        Table.setValueAt(" ",i,5); */
                        int rowNo = nmsTable.getRowCount();
                        row.addElement((rowNo+1));
                           //row.addElement(ipText.getText()+"-"+nameText.getText());
                           row.addElement(line);   
                           row.addElement((String)" ");
                           row.addElement((String) "");
                           row.addElement((String) "");
                           row.addElement((String) "");      
                            row.addElement((String) "");      
                            rows.add(row);                                     //rows is the Vector for table row.
                            Table.addNotify(); 
                  br.close();
                 if possible give me some examples.
    thank you.

    For every row you need to create a new Vector and add the data to that Vector. Then the Vector is added to the TableModel.
    If you add 6 items to the single Vector, then you will get 6 columns. So you need to create 6 Vectors and add a single item to each Vector and therefore you will end up with 6 rows with 1 column of data.

  • How to add row in a JTable at runtime.

    Hi,
    How to add a row in JTable at runtime? I am using my own TableModel object extended from AbstractTableModel.
    Thanks in advance.

    try this link... i have answered this forum.
    http://forum.java.sun.com/thread.jspa?threadID=5242581

Maybe you are looking for

  • How to create a grid like the sample of "profit Centre - Report" use sdk ?

    hi in the grid of "profit Centre - Report", it has a button,if you click it ,it can show the detaildata. it can implement many levels "Expand " and "Collaspe",but it's not implemented by group! i want to know how to implement it by ui dpi or udo . th

  • Ipod touch doesnt get recognized by windows or itunes?

    okay so just recently i would plug in my ipod touch and the little noise windows makes to say that something has been plugged in rings except itunes wont recognize it or windows will make it seem like its not even there like its plugged in but a ghos

  • Checking condition in switch step of BPM

    hi all, i am doing an 1to1 transformation where: i am converting my source into a target. the target has header 1 lineitem 1..unbouneded. lets say there are three line items: header1 lineitem lineitem lineitem i am using a send step where i am sendin

  • How do you free memory when applet ends?

    I have an applet that uses 4 jframes. Any of the frames are set to call both stop() and destroy() whenever user clicks "Exit" or "X" in upper right corner of a frame. The applet destroy() method does the following: myAOS32001Frame = null; myAOS32002F

  • Updated Internet, old hardware

    Ah, where to begin. A few months back I changed my service from triple Play to double play and upgraded my Internet speed. My first bill after the change was doubled. After calling for three months in a row and being being told different answers each