Cell L&F of JTable

hi ,
I have a JTable contructed from DeaultTableModel and
i have created a TableCellEditor which has a custom DefaultCellRenderer as its argument and
added to the table
THE PROBLEM is :
When i edit in the table cell , the editable area of the cell becomes smaller compared to the area without a TableCellEditor, how can i change it ?
and i want to change the border of the celll which is selected and its color
Any Help ? Please.
thanks.

From one of the MS windows books.....Going by the books, eh?
Well, apparently MS doesn't do so with Excel... Pressing space will simply trigger an edit!
q1) JTable should have space bar handling out of the box?
(space, CTRL+space, shift+space)
I have not seen this raised as a bug.A bug, no... a feature, maybe. Anyway, JTable provides most of the features needed for creating a table -- it's far from perfect..... adding support for CTRL+SPACE and SHIFT+SPACE is not all that hard to do.
q2) Should the enter key put an editable cell under edit and
q3) if not should the first enter key stop cell editing and a second press activate the default buttonIMHO, a good answer to your question can be found by running MS Excel and see how it's done.
The escape key will cancel editing of a cell that is under edit.and q4, q5
It should, as in Excel. But then, in Lotus 1-2-3, first escape will clear the edit buffer (unless it's empty) and the second escape will cancel editing. Who'is more programmatically correct (I don't know)?
;o)
V.V.

Similar Messages

  • Tab between cells and Editor in JTable

    I placed a cell editor in a JTable column JTextField.
    After I type something in this editor and press tab it stays in the same cell and when I press tab again then it goes to the next column.
    How can I correct this so that after I type something in the cell and press tab I want it to go to the next column directly in JTable.
    Thanks.

    I'd have to see your code to tell you what's wrong. I tried it this way and had no problem.
    TableColumn tc = table.getColumnModel().getColumn(2);
    tc.setCellEditor(new DefaultCellEditor(new JTextField()));by the way, I don't think you need to explicitly set the cell editor component to JTextField. It uses that by default.

  • Tab between cells and celleditor in JTable

    I placed a cell editor in a JTable column JTextField.
    After I type something in this editor and press tab it stays in the same cell and when I press tab again then it goes to the next column.
    How can I correct this so that After I type something in the cell and press tab I want it to go to the next column directly in JTable.
    Thanks.

    I'd have to see your code to tell you what's wrong. I tried it this way and had no problem.
    TableColumn tc = table.getColumnModel().getColumn(2);
    tc.setCellEditor(new DefaultCellEditor(new JTextField()));by the way, I don't think you need to explicitly set the cell editor component to JTextField. It uses that by default.

  • Cell border removal in JTable

    I've created a JTable with a DefaultCellRenderer. I need a way of removing the border that appears around each cell(deafult yellow colour) and instead replace it with no border or a border that goes around the entire row. Any ideas?

    add this to your code, just after you create the table:UIManager.put("Table.focusCellHighlightBorder", BorderFactory.createEmptyBorder());

  • How can i make perticular row or perticular cell Editable  of a JTable

    Dear al,
    can u help me by guiding me for the problem of...
    i am having a JTable, in which a (first)column of each row is having a checkbox field.
    If the checkbox is checked then and then i should able to modify the cells in that row where the checkbox is.
    I have created the table with AbstractTableModel of which the isCellEditable(int row, int col) method is overwriten. Whatever return value (true/false) reflects the perticular
    cells becomes editable/non-editable respectively.
    but at run time...(mean the table is created now) and now i want to make the cells editable/non-editable depending on the checkbox value...
    how can i implement it.........
    please suggest.........
    thank you.........

    here is the sample code from tutorial.......
    * TableRenderDemo.java requires no other files.
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    * TableRenderDemo is just like TableDemo, except that it explicitly initializes
    * column sizes and it uses a combo box as an editor for the Sport column.
    @SuppressWarnings("serial")
    public class TableRenderDemo extends JPanel {
         private boolean DEBUG = true;
         public TableRenderDemo() {
              super(new GridLayout(1, 0));
              JTable table = new JTable(new MyTableModel());
              // table.setEditingColumn(0);
              // table.editCellAt(0, 0);
              table.setPreferredScrollableViewportSize(new Dimension(500, 100));
              // Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              // Set up column sizes.
              initColumnSizes(table);
              // Fiddle with the Sport column's cell editors/renderers.
              setUpSportColumn(table, table.getColumnModel().getColumn(2));
              // Add the scroll pane to this panel.
              add(scrollPane);
          * This method picks good column sizes. If all column heads are wider than
          * the column's cells' contents, then you can just use
          * column.sizeWidthToFit().
         private void initColumnSizes(JTable table) {
              MyTableModel model = (MyTableModel) table.getModel();
              TableColumn column = null;
              Component comp = null;
              int headerWidth = 0;
              int cellWidth = 0;
              Object[] longValues = model.longValues;
              TableCellRenderer headerRenderer = table.getTableHeader()
                        .getDefaultRenderer();
              for (int i = 0; i < 5; i++) {
                   column = table.getColumnModel().getColumn(i);
                   comp = headerRenderer.getTableCellRendererComponent(null, column
                             .getHeaderValue(), false, false, 0, 0);
                   headerWidth = comp.getPreferredSize().width;
                   comp = table.getDefaultRenderer(model.getColumnClass(i))
                             .getTableCellRendererComponent(table, longValues, false,
                                       false, 0, i);
                   cellWidth = comp.getPreferredSize().width;
                   if (DEBUG) {
                        System.out.println("Initializing width of column " + i + ". "
                                  + "headerWidth = " + headerWidth + "; cellWidth = "
                                  + cellWidth);
                   // XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
                   column.setPreferredWidth(Math.max(headerWidth, cellWidth));
         public void setUpSportColumn(JTable table, TableColumn sportColumn) {
              // Set up the editor for the sport cells.
              JComboBox comboBox = new JComboBox();
              comboBox.addItem("Snowboarding");
              comboBox.addItem("Rowing");
              comboBox.addItem("Knitting");
              comboBox.addItem("Speed reading");
              comboBox.addItem("Pool");
              comboBox.addItem("None of the above");
              sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
              // Set up tool tips for the sport cells.
              DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
              renderer.setToolTipText("Click for combo box");
              sportColumn.setCellRenderer(renderer);
         class MyTableModel extends AbstractTableModel {
              private String[] columnNames = { "First Name", "Last Name", "Sport",
                        "# of Years", "Vegetarian" };
              private Object[][] data = {
                        { "Mary", "Campione", "Snowboarding", new Integer(5),
                                  new Boolean(false) },
                        { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) },
                        { "Kathy", "Walrath", "Knitting", new Integer(2),
                                  new Boolean(false) },
                        { "Sharon", "Zakhour", "Speed reading", new Integer(20),
                                  new Boolean(true) },
                        { "Philip", "Milne", "Pool", new Integer(10),
                                  new Boolean(false) } };
              public final Object[] longValues = { "Sharon", "Campione",
                        "None of the above", new Integer(20), Boolean.TRUE };
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return data.length;
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   return data[row][col];
              * JTable uses this method to determine the default renderer/ editor for
              * each cell. If we didn't implement this method, then the last column
              * would contain text ("true"/"false"), rather than a check box.
              public Class<?> getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
              * Don't need to implement this method unless your table's editable.
              public boolean isCellEditable(int row, int col) {
                   // Note that the data/cell address is constant,
                   // no matter where the cell appears onscreen.
                   // return false;
                   return true;
              * Don't need to implement this method unless your table's data can
              * change.
              public void setValueAt(Object value, int row, int col) {
                   if (DEBUG) {
                        System.out.println("Setting value at " + row + "," + col
                                  + " to " + value + " (an instance of "
                                  + value.getClass() + ")");
                   data[row][col] = value;
                   fireTableCellUpdated(row, col);
                   if (DEBUG) {
                        System.out.println("New value of data:");
                        printDebugData();
              private void printDebugData() {
                   int numRows = getRowCount();
                   int numCols = getColumnCount();
                   for (int i = 0; i < numRows; i++) {
                        System.out.print(" row " + i + ":");
                        for (int j = 0; j < numCols; j++) {
                             System.out.print(" " + data[i][j]);
                        System.out.println();
                   System.out.println("--------------------------");
         * Create the GUI and show it. For thread safety, this method should be
         * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("TableRenderDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Create and set up the content pane.
              TableRenderDemo newContentPane = new TableRenderDemo();
              newContentPane.setOpaque(true); // content panes must be opaque
              frame.setContentPane(newContentPane);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              // Schedule a job for the event-dispatching thread:
              // creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();

  • How to catch change cell selection in a JTable?

    I'm using a ListSelectionListener with a JTable to catch the list selection changes but it only detects row changes, and if i select a different cell but within the same row it does not trigger the event.
    Do you guys know a way to detect this event?
    Thanks!!!

    I'm using a ListSelectionListener with a JTable to catch the list selection changes but it only detects row changes,Try adding a listener for the columns as well:
    table.getTableHeader().getColumnModel().getSelectionModel().addListSelectionListener(...);

  • Custom table cell renderer in a JTable is not called

    Hello, all,
    I have the following task: I need to select several cells in a column, change the value of those cells, and once the value changes, the color of these cells should change as well. I wrote a custom cell renderer, and registered it for the object type that will use it to render the cell. However, the custom cell renderer is never called. Instead, the class name of the object is displayed in the cell.
    My code snippents are as follows:
    //Declare the table and add custom cell renderer
    JTable table = new JTable (7,7);
    table.setCellSelectionEnabled (true);
    table.setSelectionMode (ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    //Add the custom cell renderer to render objects of type Item
    table.setDefaultRenderer(Item.class, new CustomTableCellRenderer());
    //Get the selected cells and change the object type in those cells
    //This part works, since I see the app entering the for loop in the debugger, and the item.toString() value is displayed in each selected cell
    int rowIndexStart = table.getSelectedRow();
    int rowIndexEnd = table.getSelectionModel().getMaxSelectionIndex();
    int colIndex = table.getSelectedColumn();
    Item item = new Item ();
    for (int i = rowIndexStart; i<=rowIndexEnd; i++){
                  table.setValueAt(item, i, colIndex);
                 //I expect the cell to redraw now using custom cell renderer defined below, but that cell render is never called.  Instead, the item.toString() value is displayed in the cell.   What is wrong?
    //Definition of custom cell renderer. 
    //the getTableCellRendererComponent is never called, since the System.out.println never prints.  I expected this method to be called as soon as the Item object is added to the cell.  Am I wrong in expecting that?
    class CustomTableCellRenderer extends DefaultTableCellRenderer  {
        public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component cell = super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column);
            System.out.println("value: "+value.getClass()+" isSelected "+isSelected+" hasFocus "+hasFocus+" row "+row+" col "+column);
            if (this.isFocusOwner()) {
            cell.setBackground( Color.red );
            cell.setForeground( Color.white );
            return cell;
    } Please, help,
    Thank you!
    Elana

    The suggestion given above assumes that all the data in a given column is of the same type.
    If you have different types of data in different rows the you should be overriding the getCellRenderer(...) method. Something like:
    public TableCellRenderer getCellRenderer(int row, int column)
        Object o = getValueAt(row, column);
        if (o instanceof Item)
            return yourCustomRenderer
        else
            return super.getCellRenderer(row, column);
    }

  • Cell colouring in a JTable

    I am stuck with this problem. I have generated a large table and inserted the results of calculations into the 2D table. My next problem is then to highlight the rows and columns that contain the highest value. I have seeked advice on this matter before but i do not understand the reply to well. I have included the program that I am stuck at and will email the rest of the program if someone is interested in looking at it.
    Thanks
    import ccj.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    class Jacobi4 extends JFrame
         public static double c, s, t, theta, max;
         public static double eps = 0.0000005;
         public static double total = 0.0;
         public static int p, q, i, j, r, sign;
         public static int x = 0;
         public static double [][] a = new double [50][50];
         public static String result;
         public Jacobi4(int n)
              final int WIDTH = 1000;
              final int HEIGHT = 600;
              setSize(WIDTH, HEIGHT);
              addWindowListener(new WindowCloser());
              int m = n*n*n*n;
              JTable table = new JTable(m,n+1);
              JScrollPane scrollPane = new JScrollPane(table);
              scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
              //table.setFont(new Font("Monospaced", Font.PLAIN, 12));
              Container contentPane = getContentPane();
              contentPane.add(scrollPane, "Center");
              // Generate random values for the first matrix     
              for (i=0; i<n; i++)
                   for (j=0; j<n; j++)
                        a[i][j] = Numeric.randomDouble(-100, 100);
              // Prints out the values in a table
              for (i=0; i<n; i++)
                   for (j=0; j<n; j++)
                        a[i][j] = a[j];
                        table.setValueAt(""+a[i][j], i, j);
              // Calculation to find the max value in the matrix          
              max = 0;
              for (i=0; i<n; i++)
                   for (j=i+1; j<n; j++)
                        if (Math.abs(a[i][j]) > (max))
                             max = Math.abs(a[i][j]);
                             p=i; q=j;
              table.setValueAt("Row P : "+p, n-2,n);
              table.setValueAt("Column Q : "+q, n-1,n);
              table.setValueAt("Max value: "+max, n,n);
              calculation(n,p,q,table);
         public static void calculation(int n, int p, int q, JTable table)
              if ((n*max)>(eps))     //Checks for the termination condition
                   theta = 0.5*(a[q][q] - a[p][p])/a[p][q];
                             if (theta >= 0)
                                  sign = 1;
                             else
                                  sign = -1;
                        if (theta == 0)
                             t = 1;     
                        else
                             t = 1/(theta + (theta*sign) * Math.sqrt(1+Math.pow(theta,2)));
                        c = 1/Math.sqrt(1 + Math.pow(t,2));
                        s = c * t;
                        //Start the rotation procedure based on the values of p and q     
                        double matrix = rotation(n,c,s,p,q,a);
                        //Print out the new matrix
                        for (int i=0; i<n; i++)
                             for (int j=0; j<n; j++)
                                  a[i][j] = a[j][i];
                                  table.setValueAt(""+a[i][j], ((n+1)*x)+i, j);
                        // Calculation to find the max value in the matrix          
                        max = 0;
                        for (int i=0; i<n; i++)
                             for (int j=i+1; j<n; j++)
                                  if (Math.abs(a[i][j]) > (max))
                                       max = Math.abs(a[i][j]);     
                                       p=i; q=j;
                        table.setValueAt("Row P : "+p, (((n+1)*(x+1))-3),n);
                        table.setValueAt("Column Q : "+q, (((n+1)*(x+1))-2),n);
                        table.setValueAt("Max value: "+max, (((n+1)*(x+1))-1),n);
                        calculation(n,p,q,table);
              else table.setValueAt("N*Max less than eps", (((n+1)*(x+1))),n);
         public static JTextArea inputArea;
         public static JTable table;
         public static double rotation(int n,double c,double s,int p,int q, double [][]a)
              double h = c*c*a[p][p] - 2*c*s*a[p][q] + s*s*a[q][q];
              double g = s*s*a[p][p] + 2*c*s*a[p][q] + c*c*a[q][q];
              a[p][q] = c*s*(a[p][p]-a[q][q])+(c*c-s*s)*a[p][q];
              a[p][p] = h; a[q][q] = g; a[q][p] = a[p][q];
              a[p][q] = 0;     a[q][p] = 0;
              x = x+1;
              for (j=0;j<p;j++){
                   h = c*a[j][p] - s*a[j][q];
                   a[j][q] = s*a[j][p] + c*a[j][q];
                   a[q][j] = a[j][q];
                   a[j][p] = h; a[p][j] = h;
              for (j=p+1;j<q;j++){
                   h = c*a[p][j] - s*a[j][q];
                   a[j][q] = s * a[p][j] + c*a[j][q];
                   a[q][j] = a[j][q];
                   a[p][j] = h; a[j][p] = h;
              for (j=q+1;j<n;j++){
                   h = c*a[p][j] - s*a[q][j];
                   a[q][j] = s*a[p][j]+c*a[q][j];
                   a[j][q] = a[q][j];
                   a[p][j] = h; a[j][p] = h;
         return h;
         private class WindowCloser extends WindowAdapter
              public void windowClosing(WindowEvent event)
                   dispose();

    Can somebody help me with this bit. I have got the problem down to this:
    // Generate random values for the first matrix     
              for (i=0; i<n; i++)
                   for (j=0; j<n; j++)
                        a[i][j] = Numeric.randomDouble(-100, 100);                    
              // Prints out the values in a table
              for (i=0; i<n; i++)
                   for (j=0; j<n; j++)
                        a[i][j] = a[j];
                        table.setValueAt(""+a[i][j], i, j);
              // Calculation to find the max value in the matrix          
              max = 0;
              for (int i=0; i<n; i++)
                   for (int j=i+1; j<n; j++)
                        if (Math.abs(a[i][j]) > (max))
                             max = Math.abs(a[i][j]);     
                             p=i; q=j;
              table.setValueAt("Matrix : "+x, (n-3),n);
              table.setValueAt("Row P : "+p, n-2,n);
              table.setValueAt("Column Q : "+q, n-1,n);
              table.setValueAt("Max value: "+max, n,n);
              /* Set the colour of the cells containing the max value
    Now all I need to do is call a cell renderer and and colour the rows and columns that match p and q. If i get this, it would be a major load off my back. I have checked the forums and the only thing that I found close to this coloured each alternative ceill in.
    As you can see from the previous note, my JTable is creatd all in one and i add the values to the bottom of it. I do not know if there is a way of dynamically appending tables to the botton of a scrollpane.
    I am not the most experienced with java so it there is something slightly trickly in this, could you please explain it.
    If any one can help it will be much appreciated.

  • Change cell's color in jtable when user clicks on it

    Hi everyone,
    i've got a JTable, and would like to change the background of a cell when user selects it
    so i added a mouselistener over my jtable, the mousereleased method looks like this:
              public void mouseReleased(MouseEvent e) {
                   int row = table.rowAtPoint(e.getPoint());
                   int column = table.columnAtPoint(e.getPoint());
                            // help needed
              }as you see, i found the code to get the index of the cell selected, but i don't find any method in JTable class to get the cell component itself, and to alter its background color
    Please notice that the "setSelectionBackground()" in JTable isn't enough, since i would also like to change the color of cells which are not selected when the user select a cell
    how could i do that?
    Thanks in advance!
    edit: i tried the following but it does not work either
              public void mouseReleased(MouseEvent e) {
                   int row = table.rowAtPoint(e.getPoint());
                   int column = table.columnAtPoint(e.getPoint());
                   AbstractTableModel atm = (AbstractTableModel) table.getModel();
                   Component cell = table.getDefaultRenderer(CaseMemoire.class).
                   getTableCellRendererComponent(table, atm.getValueAt(row, column), true, true, row, column);
                   cell.setBackground(Color.MAGENTA);
                   table.updateUI();
              }

    ok i found how to do it
    i directly inserted this in the renderer code:
    if (row == table.getSelectedRow() && column == table.getSelectedColumn())
    cell.setBackground(etc);
    (curiously it does not work with "if (isSelected)")
    thanks :)

  • First cell not selected in JTable

    When selecting multiple cells in JTable by pressing the mousebutton and draging the selection over the cells you want to select the first cell is not selected (it stays white).
    Any suggestions on how to fix this?

    I am running in M$ Windows.
    The first cell (anywhere in the Table) when you press the mouse to select a range of cells is present by color white (depend on L&F setting).
    The white color on first cell does not means the first cell is not selected!!!
    ( The first cell is selected, but present by white color to show you that is the start point )
    (if you use M$ Excel, that is the same effect presentation! )
    Hope this helps.

  • Focus cell editor component of JTable when starting editing by typing

    Hello, everybody.
    We all know that the JTable component doesn't actually focus the actual cell editor component when editing is started by typing. But I need this functionality in an application of mine. So, I ask: is there a way to transfer focus to the editor component when editing is started by typing?
    Thank you.
    Marcos

    Well, I think that I've found it: JTable#setSurrendersFocusOnKeystroke.
    Marcos

  • Stopping cell editing in a JTable using a JComboBox editor w/ AutoComplete

    Hi there! Me again with more questions!
    I'm trying to figure out the finer parts of JTable navigation and editing controls. It's getting a bit confusing. The main problem I'm trying to solve is how to make a JTable using a combo box editor stop editing by hitting the 'enter' key in the same fashion as a JTextField editor. This is no regular DefaultCellEditor though -- it's one that uses the SwingX AutoCompleteDecorator. I have an SSCCE that demonstrates the issue:
    import java.awt.Component;
    import java.awt.EventQueue;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JTable;
    import javax.swing.WindowConstants;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableModel;
    import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
    public class AutoCompleteCellEditorTest extends JFrame {
      public AutoCompleteCellEditorTest() {
        JTable table = new JTable();
        Object[] items = {"A", "B", "C", "D"};
        TableModel tableModel = new DefaultTableModel(2, 2);
        table.setModel(tableModel);
        table.getColumnModel().getColumn(0).setCellEditor(new ComboCellEditor(items));
        getContentPane().add(table);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        pack();
      private class ComboCellEditor extends AbstractCellEditor implements TableCellEditor {
        private JComboBox comboBox;
        public ComboCellEditor(Object[] items) {
          this.comboBox = new JComboBox(items);
          AutoCompleteDecorator.decorate(this.comboBox);
        public Object getCellEditorValue() {
          return this.comboBox.getSelectedItem();
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
          comboBox.setSelectedItem(value);
          return comboBox;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() {
            new AutoCompleteCellEditorTest().setVisible(true);
    }Problem 1: Starting to 'type' into the AutoCompleteDecorate combo box doesn't cause it to start editing. You have to hit F2, it would appear. I've also noticed this behaviour with other JComboBox editors. Ideally that would be fixed too. Not sure how to do this one.
    Problem 2: After editing has started (say, with the F2 key), you may start typing. If you type one of A, B, C, or D, the item appears. That's all good. Then you try to 'complete' the edit by hitting the 'enter' key... and nothing happens. The 'tab' key works, but it puts you to the next cell. I would like to make the 'enter' key stop editing, and stay in the current cell.
    I found some stuff online suggesting you take the input map of the table and set the Enter key so that it does the same thing as tab. Even though that's not exactly what I desired (I wanted the same cell to be active), it didn't work anyway.
    I also tried setting a property on the JComboBox that says that it's a table cell editor combo box (just like the DefaultCellEditor), but that didn't work either. I think the reason that fails is because the AutoCompleteDecorator sets isEditable to true, and that seems to stop the enter key from doing anything.
    After tracing endless paths through processKeyBindings calls, I'm not sure I'm any closer to a solution. I feel like this should be a fairly straightforward thing but I'm having a fair amount of difficulty with it.
    Thanks for any direction you can provide!

    Hi Jeanette,
    Thanks for your advice. I looked again at the DefaultCellEditor. You are correct that I am not firing messages for fireEditingStopped() and fireEditingCancelled(). Initially I had copied the behaviour from DefaultCellEditor but had trimmed it out. I assumed that since I was extending AbstractCellEditor and it has them implemented correctly that I was OK. But I guess that's not the case! The problem I'm having with implementing the Enter key stopping the editing is that:
    1) The DefaultCellEditor stops cell editing on any actionPerformed. Based on my tests, actionPerformed gets called whenever a single key gets pressed. I don't want to end the editing on the AutoCompleteDecorated box immediately -- I'd like to wait until the user is happy with his or her selection and has hit 'Enter' before ending cell editing. Thus, ending cell editing within the actionPerformed listener on the JComboBox (or JXComboBox, as I've made it now) will not work. As soon as you type a single key, if it is valid, the editing ends immediately.
    2) I tried to add a key listener to the combo box to pick up on the 'Enter' key and end the editing there. However, it appears that the combo box does not receive the key strokes. I guess they're going to the AutoCompleteDecorator and being consumed there so the combo box does not receive them. If I could pick up on the 'Enter' key there, then that would work too.
    I did more reading about input maps and action maps last night. Although informative, I'm not sure how far it got me with this problem because if the text field in the AutoCompleteDecorator takes the keystroke, I'm not sure how I'm going to find out about it in the combo box.
    By the way, when you said 'They are fixed... in a recent version of SwingX', does that mean 1.6.2? That's what I'm using.
    Thanks!
    P.S. - Maybe I should create a new question for this? I wanted to mark your answer as helpful but I already closed the thread by marking the answer to the first part as correct. Sorry!
    Edited by: aardvarkk on Jan 27, 2011 7:41 AM - Added SwingX versioning question.

  • Cell Editor for a JTable within A JTable Cell

    My individual cells each contain a seperate JTable and I need to write a cell editor for it. I'm not really sure how to write one so if someone show me where I can find some useful examples of such a cell editor I would greatly appreciate it. Thank you for your time. :-)

    So, you have a big table whose cells each contain a little table. I assume you already have the little tables working correctly with cell editors and so on, and you want to write a cell editor for the big table. Correct?
    My problem with this is that I can't imagine how this would actually work in practice. Suppose I click on a cell in the big table; then the cell renderer displays the appropriate little table. At this point should I see one of the cells in that little table selected, and should I be able to use the Tab key to move around the little table? And if so, then I can't use the Tab key to move around the big table. Next, suppose I press F2 indicating that I want to edit the little table. What should change? Should I now be able to tab around the little table, whereas I couldn't before? And if so, how do I indicate that I have stopped editing the little table? Pressing Enter indicates to the little table's cell editor that its editing is finished, but how should I tell the big table's cell editor that its editing is finished?
    Perhaps if you can answer this, you may have a better idea of how to solve your problem. Sorry I only have questions and not answers.

  • How to remove cells interection line in JTable

    Hello
    I am new to Java Programming
    I am facing a problem which i did not know how to solve so i need help from experts of this forum
    I have JTable of lets say 5 columns and from that i want to hide some columsn e.g i want to get only column 0(or ist column) and column 5(5th column) visible to me and not the inbetween columns(i.e 2,3,4) so i coded it like this:
    for(int count=0;count< ConnectedDrivestable.getColumnCount();count++)
                   tcm = ConnectedDrivestable.getColumnModel();
                   cm=tcm.getColumn(count);
                  if( count==0 || count==4)
                       cm.setPreferredWidth(15);
                   cm.setMinWidth(0);                   
                       cm.setMaxWidth(15);                   
                  else {
                       //ConnectedDrivestable.removeColumn(cm);
                           //ConnectedDrivestable.removeColumn(tcm.getColumn(count));
                       cm.setPreferredWidth(0);
                   cm.setMinWidth(0);          
                       cm.setMaxWidth(0);
              }where ConnectedDrivestable is my JTable of lets say 5 rows and 5 columns
    tcm is TableColumnModel and cm is TableColumn object
    But the problem is that i am getting vertical line in between and that is the intersection line of column 1 and column 5(i.e the intersection line of two columns that are visible) i dont want this in between vertical line to appear
    I really dont know how to fix this problem i have searched on internet but unable to find the appropriate solution to it
    Also as shown in my code i tried to work with removeColumn method which documentation says should remove the desired columns but i dont know why it is not functioing for my case the way i acpected am i doing something wrong or?
    So urgent help from people here is required
    Thanks in advance
    Imran

    Hello
    Thanks for reply and thanks for help
    Do please tell me that i am rendering cells of JTable with JLabel it is working fine but i want to span JLabel onto multicells in the same row
    Second i want to change the size of JLabel so that if not needed JLabel did not cover the whole Cell
    A bit of code which i am using to do cel rendering is attched for your kind considerations
    ConnectedDrivestable.getColumnModel().getColumn(1).setCellRenderer((new  DefaultTableCellRenderer ()
                   public Component getTableCellRendererComponent(JTable table, Object value,
                             boolean isSelected,
                             boolean hasFocus,
                             int row, int column)
                        JLabel Jlbl=new JLabel();
                        if(row==2)
                             ((JComponent)Jlbl).setOpaque(true); //if comp is a JLabel:Necessary
                             //Jlbl.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                             Jlbl.setBackground(Color.GREEN);
                             Jlbl.setLocation(row,column);
                             System.out.print("The Column number is : "+column);
                             System.out.print("The answer is: "+ column+2);
                             ((JComponent)Jlbl).setMinimumSize(new Dimension(1,1));
                             ((JComponent)Jlbl).setMaximumSize(new Dimension(0,0));
                        return Jlbl;
                        //return comp;
              }));Another piece of code which i got from internet for doing the same is
    ConnectedDrivestable.getColumnModel().getColumn(2).setCellRenderer((new  DefaultTableCellRenderer ()
                   public Component getTableCellRendererComponent(JTable table, Object value,
                             boolean isSelected,
                             boolean hasFocus,
                             int row, int column)
                        Component comp = super.getTableCellRendererComponent
                             (table, value, isSelected, hasFocus, row, column);                         
                        //((JComponent)comp).setBorder(new LineBorder(Color.BLACK));                         
                        if(row==2 && column==2)
                             //((JComponent)comp).setBorder(new LineBorder(Color.BLACK));
                             comp.setBackground(Color.GREEN);
                             ((JComponent)comp).setMinimumSize(new Dimension(1,1));
                             ((JComponent)comp).setMaximumSize(new Dimension(1,1));                                   
                        else
                             comp.setBackground(Color.white);
                        return comp;
              }));These both work but as i tried to change the size of JLabel in the Cells it did not work also if i wanted to span JLabels to multiple cells(Column) is it not working
    Also as in code snippet i am trying to set the border which works fine but what i want is that after spanning JLabel to multiple cells then i want border along this how to do this help in this regard too?might if i could span JLabel to diffrent columns might i able to set border aroung them too
    I am putting under old forum topic this question as it is realted to my same problem so do please apologize me.
    I do need urgent help in this regard so kind help is needed
    Regards

  • Remove Cell Selection Border in JTable

    Hi
    I have multiple columns in JTable populated with data. When the row is selected, the row changes colour. It also places a border around the cell that is selected within the row.
    Is there some way to remove this border?
    Any help would be appreciated.
    Thanks
    Gregg

    Hi,
    you need a different tableCellRenderer. Read:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#custom
    There are also code examples.
    Phil

Maybe you are looking for

  • NF-e 3.10 - NF writer com informação de comércio exterior

    Boa tarde, senhores. Estamos implantando a NF-e 3.10 em minha empresa e estou com uma dúvida quanto ao preenchimento das tags de comércio exterior: Tags Descrição UFSaidaPais Sigla da UF de Embarque ou de transposição de fronteira xLocExporta Descriç

  • Cooling problems with Satellite A300-1B0: ventilator is not stopping

    Hi users, i m new in Linux and Ubuntu, i installed ubuntu 8.10 last week; All things are ok, boot menu ok because i have XP, network connection ethernet and wireless, updates ok, packages ok! just one thing that make me "" it's the cooling ventilator

  • How do i get my old favorites list back on tool bar?

    I just downloaded Firefox but my favorites list is missing.How do I get it back on the tool bar?

  • Problem in Using webdynpro Button outside Interactive Form

    Hi Experts, I am using the WebDynpro SUBMIT button  Outside the interactiveForm My question infact was, that I want to use the WebDynpro native button and place it outside the form. I have written the code in the onActionSubmit() of this button to bi

  • Mac Pro Harpertown vs Nehalem

    Hi there Today I am a lucky boy indeed - we will be hiring a new designer and as the perks of being top of the designer chain of command they inherit my Mac and I get to buy a shiney new Mac Pro. My quandary is this: I currently have a 2008 Mac Pro w