Hightlight text in JTable Cells on Tab

Hi,
I have built a Java front end for AAirlines. It has all the functionality that is expected of it, except the user wishes to have the contents of each cell highlighted on a Tab(Setting the cursor to the end of the text seems to be the default which I am unable to override). Any ideas greatly appreciated.
Anil

Hi,
I followed your suggestion and wrote the following code to use the DefaultCellEditor. It doesnt seem to work. My DataModel for JTable is an AbstractTableModel subclass. Is there anything I need to do in the model too???
If you have any code snippets that actually does the job of highlighting a cell on tabbing, it will be a great help.
final JTextField tf = new JTextField("xyz");
tf.selectAll();
TableCellEditor editor = new DefaultCellEditor(tf){
public Object getCellEditorValue(){ 
return tf.getText();
public Component getComponent()
return tf;
public boolean isCellEditable(EventObject eo)
return true;
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column){
tf.setText((String) value);
tf.requestFocus();
tf.selectAll();
return tf;
jTable1.setDefaultEditor(String.class, editor);
Anil

Similar Messages

  • Centering text in JTable cells

    How do I center the text in JTable cells? By default, all data is left aligned.
    Thanks,
    Jason

    Read up on cell renderers from the Swing tutorial on "Using Tables":
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender
    Here's an example to get you started.
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.text.*;
    public class TableRenderer extends JFrame
        public TableRenderer()
            String[] columnNames = {"Date", "String", "Integer", "Decimal", "Boolean"};
            Object[][] data =
                {new Date(), "A", new Integer(1), new Double(5.1), new Boolean(true)},
                {new Date(), "B", new Integer(2), new Double(6.2), new Boolean(false)},
                {new Date(), "C", new Integer(3), new Double(7.3), new Boolean(true)},
                {new Date(), "D", new Integer(4), new Double(8.4), new Boolean(false)}
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            JTable table = new JTable( model )
                //  Returning the Class of each column will allow different
                //  renderers to be used based on Class
                public Class getColumnClass(int column)
                    return getValueAt(0, column).getClass();
            JScrollPane scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane );
            //  Create cell renderer
            TableCellRenderer centerRenderer = new CenterRenderer();
            //  Use renderer on a specific column
            TableColumn column = table.getColumnModel().getColumn(3);
            column.setCellRenderer( centerRenderer );
            //  Use renderer on a specific Class
            table.setDefaultRenderer(String.class, centerRenderer);
        public static void main(String[] args)
            TableRenderer frame = new TableRenderer();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setVisible(true);
        **  Center the text
        class CenterRenderer extends DefaultTableCellRenderer
            public CenterRenderer()
                setHorizontalAlignment( CENTER );
            public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                return this;

  • Skipping jTable cells with tab

    When a user presses tab, the selected cell moves to the next cell to the right.
    Is there a way that when the user presses tab, that the next cell will be skipped, and the following one will be selected?
    Thanks

    Ok I gave you the weekend :)
    bump
    I thought it would be in the DefaultCellEditor, but no luck there.
    Any help is appreciated.

  • Validate user-entered text in JTable

    How do I validate user entered text in JTable cell, so only the values 1234567890. are acceptet? The cell should contain only doubles....

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class aslan extends JFrame {
      public aslan() {
        TableModel model = new CustomTableModel();
        JTable table = new JTable(model);
        getContentPane().add(new JScrollPane(table), "Center");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300,200);
        setLocation(300,300);
        setVisible(true);
      private class CustomTableModel extends AbstractTableModel {
        String[] headings = new String[] {
          "Cost", "Item", "Type"
        Object[][] data = new Object[][] {
          { new Double(12.75), "glue",   "tube" },
          { new Double(15.20), "hammer", "claw" },
          { new Double(8.32),  "saw",    "hack" }
        public int getRowCount() {
          return data.length;
        public int getColumnCount() {
          return data[0].length;
        public Object getValueAt(int row, int column) {
          return data[row][column];
        public void setValueAt(Object value, int row, int column) {
          data[row][column] = value;
          fireTableDataChanged();
        public String getColumnName(int column) {
          return headings[column];
        public Class getColumnClass(int column) {
          return data[0][column].getClass();
        public boolean isCellEditable(int row, int column) {
          return true;
      public static void main(String[] args) {
        new aslan();
    }

  • JTable Cell text selection Problem.

    I am using Tab key while navigating with the Cells.While focus reaches into a cell,the cell is selected but not the cell content.So I use BACKSPACE to delete each word of the cell.I want to Select a cell content(i.e. Text) when I am move Tab keys to select cells.Please help me..........,u may send a mail at [email protected]

    Do u need this feature to the whole table or else for the perticular cell in the table?
    Are you using your own renderer or editor to the perticular cell ?,
    this issue is related to Renderer and Editor, so if i know your requirement , then only it is easy to implement.

  • How do I change the colour of text in a cell in a JTable?

    I am trying to change the color of the text in a single cell in a JTable. I have tried not adding a cell renderer and it changes the colour of text in all cells.
    I have tried adding a cell renderer to the table and it does the same ie all cells text colour changes.
    I am able to add a cell renderer to a column and it changes all the cells in the column.
    I cannot figure out how to change just one single cell's text colour without effecting the other cells.

    Ok, so if i create my own cell renderer do I set it as the default renderer for the whole table i.e.
    table.setDefaultRenderer(MyCellRenderer, renderer);
    Does this set one cell renderer for the whole table or is there an individual one for each cell?

  • Centering text in a cell in a JTable

    Hi,
    I have a program that reads in data from a text file and display it in a JTable. My problem is that the data in each cell is not centered, it is left justified within that cell.
    How can I fix this.
    --kirk                                                                                                                                                                                                                                                                                                                                                                                                                                            

    To align a text inside a cell you have to go through the rendering classes of a Jtable. You can do lots of formatting by using a render class. Heres my code that i use.
    1. The first code aligns your data centered inside the cell.
    2. The second code aligns it like code1 but has an additional character to be printed beside your data inside the text.
    ///////////// TO USE THE RENDER CODE IN YOUR APPLICATION /////
    TableColumn col1 = table.getColumnModel().getColumn(1);
    col1.setCellRenderer( new SimpleRenderer());
    or
    TableColumn col1 = table.getColumnModel().getColumn(1);
    col1.setCellRenderer( new SimpleRenderer( "$" ));
    ///////////// RENDER CODE IS HERE //////////////
    import javax.swing.table.*;
    import javax.swing.border.*;
    import javax.swing.*;
    import java.awt.*;
    public class SimpleRenderer extends JLabel implements TableCellRenderer
         Border unselectedBorder = null;
         Border selectedBorder = null;
         String text = "";
         Color foreColor = Color.black;
         Color backColor = new java.awt.Color( 217,217,255 );
         Color selectedColor = new java.awt.Color( 217,217,255 );
         public SimpleRenderer()
         super();
         setHorizontalAlignment( JLabel.CENTER );
         setOpaque( true );
         } // end of CONSTRUCTOR
         public SimpleRenderer( Color foreGround, Color backGround )
         super();
         setHorizontalAlignment( JLabel.CENTER );
         setOpaque( true );
         this.foreColor = foreGround;
         this.backColor = backGround;
         } // end of CONSTRUCTOR
         public SimpleRenderer( String data )
         super();
         text = data;
         setHorizontalAlignment( JLabel.CENTER );
         setOpaque( true );
         } // end of CONSTRUCTOR
         public Component getTableCellRendererComponent(
              JTable table, Object object, boolean isSelected, boolean hasFocus,
                                                                                    int row, int column)
         try
              if ( backColor != null )
                   if ( (row % 2 ) == 1 )
                             setBackground( backColor );
                   else
                             setBackground( Color.white );
              if ( foreColor != null )
                   setForeground( foreColor );
              if ( hasFocus )
                   if ( isSelected )
                             setBackground( selectedColor );
                   else
                             setBackground( Color.white );
              String newData = "" + object;
              if ( newData.trim().equals( "" ))
                   setText( "" );
              else
                   setText( text + " " + object );
              if (isSelected)
              if (selectedBorder == null)
                   Border border, raisedBevel, loweredBevel;
                   raisedBevel = BorderFactory.createRaisedBevelBorder();
                   loweredBevel = BorderFactory.createLoweredBevelBorder();
                   Border colorLine = BorderFactory.createLineBorder(Color.red);
                   border = BorderFactory.createCompoundBorder( raisedBevel,loweredBevel);
                   selectedBorder = BorderFactory.createCompoundBorder( border, colorLine);
              setBorder(selectedBorder);
              else
              if (unselectedBorder == null)
                        unselectedBorder = BorderFactory.createMatteBorder(0,0,0,0,
                        table.getBackground());
              setBorder(unselectedBorder);
         catch( ClassCastException e )
         return this;
         } // end of GETTABLECELLRENDERERCOMPONENT method.
         public void setForeColor( Color data )
         foreColor = data;
         } // end of SETFORECOLOR method.
         public void setBackColor( Color data )
         backColor = data;
         } // end of SETBACKCOLOR method.
    } /** end of CLASS **/
    /////////////

  • Tab transversal while using JTextArea as a JTable cell editor..

    I'm working on a project that will use a JTable with a JTextArea cell editor to create a chart for classroom scheduling. Searching on Google, I found a way to use a JTextArea as a cell editor and render the cell properly. However, when editing a cell, pressing the Tab key inserts a tab, rather than leaving the cell and going to the next one, as happens with just a regular JTable. In fact, none of the keyboard shortcuts that work on a JTable work once the JTextArea cell editor is used. Does anyone know of any way to resolve this? Below is some code I'm using to create a sample GUI, just to verify that I can do this. Another question is would it be easier to use a bunch of JLabels and JTextAreas, remove the padding from those JTextAreas, and try to allow for Tab transversals between stand-alone JTextAreas, rather than JTextAreas as JTable cell editors?
    Thanks!
    package edu.elon.table;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class GUI
         private JFrame frame;
         private String[] columnNames = {"Classroom", "8:00-9:10", "9:25-10:35",
              "10:50-12:00", "12:15-1:25", "1:40-2:50", "1:40-3:20 (MW)",
              "3:35-5:15 (MW)", "5:30-7:10 (MW)"};
         private Object[][] data = {columnNames,
              {"ALAM 201 (42)\nENG 110 LAB", "", "", "", "", "", "", "", ""},
              {"ALAM 202 (42)\nDP/DVD", "", "", "", "", "", "", "", ""},
              {"ALAM 203 (38)\nDP/DVD", "", "", "", "", "", "", "", ""},
              {"ALAM 205 (40)\n", "", "", "", "", "", "", "", ""},
              {"ALAM 206 (39)\nSINK, TV/VCR", "", "", "", "", "", "", "", ""},
              {"ALAM 207 (40+)\nDP/DVD", "", "", "", "", "", "", "", ""},
              {"ALAM 214 (38)\nTV/VCR", "", "", "", "", "", "", "", ""},
              {"ALAM 215 (42)\nTV/VCR", "", "", "", "", "", "", "", ""},
              {"ALAM 216 (42)\n", "", "", "", "", "", "", "", ""},
              {"ALAM 301 (40)\nTV/VCR", "", "", "", "", "", "", "", ""},
              {"ALAM 302 (38)\nDP/DVD", "", "", "", "", "", "", "", ""},
              {"ALAM 304 (35)\nFRENCH", "", "", "", "", "", "", "", ""},
              {"ALAM 314 (30)\nDP, PSY, COMPUTER ASSISTED", "", "", "", "", "", "",
              {"ALAM 315 (40)\nPC LAB, DP/DVD", "", "", "", "", "", "", "", ""}};
         private JTable table;
         public GUI()
              frame = new JFrame();
              table = new JTable(data, columnNames);
              table.setRowHeight(table.getRowHeight()*2);
              TableColumnModel cModel = table.getColumnModel();
              TextAreaRenderer renderer = new TextAreaRenderer();
              TextAreaEditor editor = new TextAreaEditor();
              for (int i = 0; i < cModel.getColumnCount(); i++)
                   cModel.getColumn(i).setCellRenderer(renderer);
                   cModel.getColumn(i).setCellEditor(editor);
              frame.setLayout(new GridLayout(1,0));
              frame.add(table);
              frame.pack();
              frame.setVisible(true);
    public static void main (String[] args)
    GUI gui = new gui();
    * Written by Dr. Heinz Kabutz, found through online newsletter via Google.
    class TextAreaRenderer extends JTextArea
    implements TableCellRenderer {
    private final DefaultTableCellRenderer adaptee =
    new DefaultTableCellRenderer();
    /** map from table to map of rows to map of column heights */
    private final Map cellSizes = new HashMap();
    public TextAreaRenderer() {
    setLineWrap(true);
    setWrapStyleWord(true);
    public Component getTableCellRendererComponent(//
    JTable table, Object obj, boolean isSelected,
    boolean hasFocus, int row, int column) {
    // set the colours, etc. using the standard for that platform
    adaptee.getTableCellRendererComponent(table, obj,
    isSelected, hasFocus, row, column);
    setForeground(adaptee.getForeground());
    setBackground(adaptee.getBackground());
    setBorder(adaptee.getBorder());
    setFont(adaptee.getFont());
    setText(adaptee.getText());
    // This line was very important to get it working with JDK1.4
    TableColumnModel columnModel = table.getColumnModel();
    setSize(columnModel.getColumn(column).getWidth(), 100000);
    int height_wanted = (int) getPreferredSize().getHeight();
    addSize(table, row, column, height_wanted);
    height_wanted = findTotalMaximumRowSize(table, row);
    if (height_wanted != table.getRowHeight(row)) {
    table.setRowHeight(row, height_wanted);
    return this;
    private void addSize(JTable table, int row, int column,
    int height) {
    Map rows = (Map) cellSizes.get(table);
    if (rows == null) {
    cellSizes.put(table, rows = new HashMap());
    Map rowheights = (Map) rows.get(new Integer(row));
    if (rowheights == null) {
    rows.put(new Integer(row), rowheights = new HashMap());
    rowheights.put(new Integer(column), new Integer(height));
    * Look through all columns and get the renderer. If it is
    * also a TextAreaRenderer, we look at the maximum height in
    * its hash table for this row.
    private int findTotalMaximumRowSize(JTable table, int row) {
    int maximum_height = 0;
    Enumeration columns = table.getColumnModel().getColumns();
    while (columns.hasMoreElements()) {
    TableColumn tc = (TableColumn) columns.nextElement();
    TableCellRenderer cellRenderer = tc.getCellRenderer();
    if (cellRenderer instanceof TextAreaRenderer) {
    TextAreaRenderer tar = (TextAreaRenderer) cellRenderer;
    maximum_height = Math.max(maximum_height,
    tar.findMaximumRowSize(table, row));
    return maximum_height;
    private int findMaximumRowSize(JTable table, int row) {
    Map rows = (Map) cellSizes.get(table);
    if (rows == null) return 0;
    Map rowheights = (Map) rows.get(new Integer(row));
    if (rowheights == null) return 0;
    int maximum_height = 0;
    for (Iterator it = rowheights.entrySet().iterator();
    it.hasNext();) {
    Map.Entry entry = (Map.Entry) it.next();
    int cellHeight = ((Integer) entry.getValue()).intValue();
    maximum_height = Math.max(maximum_height, cellHeight);
    return maximum_height;
    * Written by Dr. Heinz Kabutz, found through online newsletter via Google.
    class TextAreaEditor extends DefaultCellEditor
    public TextAreaEditor() {
         super(new JTextField());
    final JTextArea textArea = new JTextArea();
    textArea.setWrapStyleWord(true);
    textArea.setLineWrap(true);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(null);
    editorComponent = scrollPane;
    delegate = new DefaultCellEditor.EditorDelegate() {
    public void setValue(Object value)
    textArea.setText((value != null) ? value.toString() : "");
    public Object getCellEditorValue()
    return textArea.getText();
    }

    Using the KeyEvent manager and playing around with the JTextArea, I was able to get a JTable using JTextAreas as the cell editors that worked very close to the way the regular JTable works. You have to hit Tab twice to shift focus to another cell, or hit Tab once and then an arrow key. Also, Alt-Enter will allow you to enter a cell for editing. All of the changes were made to the TextAreaEditor class, which should now read as follows:
    class TextAreaEditor extends DefaultCellEditor implements KeyListener
         private int lastKeyCode;
         public TextAreaEditor(final JTable table) {
              super(new JTextField());
              lastKeyCode = KeyEvent.CTRL_DOWN_MASK;
              final JTextArea textArea = new JTextArea();
              textArea.setWrapStyleWord(true);
              textArea.setLineWrap(true);
              textArea.addKeyListener(this);
              textArea.setFocusable(true);
              textArea.setFocusAccelerator((char) KeyEvent.VK_ENTER);
              JScrollPane scrollPane = new JScrollPane(textArea);
              scrollPane.setBorder(null);
              scrollPane.setFocusable(false);
              editorComponent = scrollPane;
              delegate = new DefaultCellEditor.EditorDelegate() {
                   public void setValue(Object value) {
                        textArea.setText((value != null) ? value.toString() : "");
                   public Object getCellEditorValue() {
                        return textArea.getText();
         public void keyTyped(KeyEvent ke)
              // TODO Auto-generated method stub
         public void keyPressed(KeyEvent ke)
              if (ke.getKeyCode() == KeyEvent.VK_TAB)
                   ke.consume();
                   KeyboardFocusManager.getCurrentKeyboardFocusManager()
                             .focusNextComponent();
                   return;
              if (ke.getKeyCode() == KeyEvent.VK_TAB && ke.isShiftDown())
                   ke.consume();
                   KeyboardFocusManager.getCurrentKeyboardFocusManager()
                             .focusPreviousComponent();
                   return;
              if ((lastKeyCode == KeyEvent.CTRL_DOWN_MASK) &&
                        (ke.getKeyCode() == KeyEvent.VK_ENTER))
                   ke.consume();
                   editorComponent.requestFocus();
              else
                   lastKeyCode = ke.getKeyCode();
         public void keyReleased(KeyEvent ke)
              // TODO Auto-generated method stub
         }

  • How to blink the text with in JTable Cell?

    Hi Friends,
    I am relatively new to Java Swings. I have got a requirement to blink the text with in the JTable cell conditionally. Please help with suggestions or sample codes if any.
    Thanks in Advance.
    Satya.

    I believe Swing components support HTML tags.
    So you might be able to wrap your text in <BLINK>I am blinking !</BLINK>
    tags.
    If that doesn't work, you probably have to create your own cell renderer, and force a component repaint every second or so... messy.
    regards,
    Owen

  • Can not show the JCheckBox in JTable cell

    I want to place a JCheckBox in one JTable cell, i do as below:
    i want the column "d" be a check box which indicates "true" or "false".
    String[] columnNames = {"a","b","c","d"};
    Object[][] rowData = {{"", "", "", Boolean.FALSE}};
    tableModel = new DefaultTableModel(rowData, columnNames);
    dataTable = new JTable(tableModel);
    dataTable.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(new JCheckBox()));
    But when i run it, the "d" column show the string "false" or "true", not the check box i wanted.
    I do not understand it, can you help me?
    Thank you very much!
    coral9527

    Do not use DefaultTableModel, create your own table model and you should implement the method
    getColumnClass to display the boolean as checkbox ...
    I hope the following colde snippet helps you :
    class MyModel extends AbstractTableModel {
              private String[] columnNames = {"c1",
    "c2"};
    public Object[][] data ={{Boolean.valueOf(true),"c1d1"}};
         public int getColumnCount() {
         //System.out.println("Calling getColumnCount");
         return columnNames.length;
    public int getRowCount() {
    //System.out.println("Calling row count");
    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 true;
    * Don't need to implement this method unless your table's
    * data can change.
    public void setValueAt(Object value, int row, int col) {
    data[row][col] = value;
    fireTableCellUpdated(row, col);

  • Multiple Lines in a Jtable Cell

    I am trying to place multiple lines in a single cell of Jtable
    The text Of the cell comes from the database.I am trying to do it using a JLabel .If anyone can help me please do so
    thanks
    kishore
    [email protected]

    It can be done but it is quite a lot of work. Basically you have to produce your own cell renderer and use that instead. A good book on swing will tell you how to do it.

  • Center text in JTable

    Hello!
    Could anyone help me out how center text (or left/right aligment) in JTable cells?
    Best Regards
    Staffan

    Use your own [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender]renderer?
    : jay

  • Problem in event handling of combo box in JTable cell

    Hi,
    I have a combo box as an editor for a column cells in JTable. I have a event listener for this combo box. When ever I click on the JTable cell whose editor is combo box,
    I get the following exception,
    Exception occurred during event dispatching:
    java.lang.NullPointerException
         at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.setDispatchComponent(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.mousePressed(Unknown Source)
         at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Can any one tell me how to over come this problem.
    Thanks,
    Raghu

    Here's an example of the model I used in my JTable. I've placed 2 comboBoxes with no problems.
    Hope this helps.
    public class FileModel5 extends AbstractTableModel
    public boolean isEditable = false;
    protected static int NUM_COLUMNS = 3;
    // initialize number of rows to start out with ...
    protected static int START_NUM_ROWS = 0;
    protected int nextEmptyRow = 0;
    protected int numRows = 0;
    static final public String file = "File";
    static final public String mailName = "Mail Id";
    static final public String postName = "Post Office Id";
    static final public String columnNames[] = {"File", "Mail Id", "Post Office Id"};
    // List of data
    protected Vector data = null;
    public FileModel5()
    data = new Vector();
    public boolean isCellEditable(int rowIndex, int columnIndex)
    // The 2nd & 3rd column or Value field is editable
    if(isEditable)
    if(columnIndex > 0)
    return true;
    return false;
    * 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();
    * Retrieves number of columns
    public synchronized int getColumnCount()
    return NUM_COLUMNS;
    * Get a column name
    public String getColumnName(int col)
    return columnNames[col];
    * Retrieves number of records
    public synchronized int getRowCount()
    if (numRows < START_NUM_ROWS)
    return START_NUM_ROWS;
    else
    return numRows;
    * Returns cell information of a record at location row,column
    public synchronized Object getValueAt(int row, int column)
    try
    FileRecord5 p = (FileRecord5)data.elementAt(row);
    switch (column)
    case 0:
    return (String)p.file;
    case 1:
    return (String)p.mailName;
    case 2:
    return (String)p.postName;
    catch (Exception e)
    return "";
    public void setValueAt(Object aValue, int row, int column)
    FileRecord5 arow = (FileRecord5)data.elementAt(row);
    arow.setElementAt((String)aValue, column);
    fireTableCellUpdated(row, column);
    * Returns information of an entire record at location row
    public synchronized FileRecord5 getRecordAt(int row) throws Exception
    try
    return (FileRecord5)data.elementAt(row);
    catch (Exception e)
    throw new Exception("Record not found");
    * Used to add or update a record
    * @param tableRecord
    public synchronized void updateRecord(FileRecord5 tableRecord)
    String file = tableRecord.file;
    FileRecord5 p = null;
    int index = -1;
    boolean found = false;
    boolean addedRow = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord5)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    { //update
    data.setElementAt(tableRecord, index);
    else
    if (numRows <= nextEmptyRow)
    //add a row
    numRows++;
    addedRow = true;
    index = nextEmptyRow;
    data.addElement(tableRecord);
    //Notify listeners that the data changed.
    if (addedRow)
    nextEmptyRow++;
    fireTableRowsInserted(index, index);
    else
    fireTableRowsUpdated(index, index);
    * Used to delete a record
    public synchronized void deleteRecord(String file)
    FileRecord5 p = null;
    int index = -1;
    boolean found = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord5)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    data.removeElementAt(i);
    nextEmptyRow--;
    numRows--;
    fireTableRowsDeleted(START_NUM_ROWS, numRows);
    * Clears all records
    public synchronized void clear()
    int oldNumRows = numRows;
    numRows = START_NUM_ROWS;
    data.removeAllElements();
    nextEmptyRow = 0;
    if (oldNumRows > START_NUM_ROWS)
    fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);
    fireTableRowsUpdated(0, START_NUM_ROWS - 1);
    * Loads the values into the combo box within the table for mail id
    public void setUpMailColumn(JTable mapTable, ArrayList mailList)
    TableColumn col = mapTable.getColumnModel().getColumn(1);
    javax.swing.JComboBox comboMail = new javax.swing.JComboBox();
    int s = mailList.size();
    for(int i=0; i<s; i++)
    comboMail.addItem(mailList.get(i));
    col.setCellEditor(new DefaultCellEditor(comboMail));
    //Set up tool tips.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for mail Id list");
    col.setCellRenderer(renderer);
    //Set up tool tip for the mailName column header.
    TableCellRenderer headerRenderer = col.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the Mail Id to see a list of choices");
    * Loads the values into the combo box within the table for post office id
    public void setUpPostColumn(JTable mapTable, ArrayList postList)
    TableColumn col = mapTable.getColumnModel().getColumn(2);
    javax.swing.JComboBox combo = new javax.swing.JComboBox();
    int s = postList.size();
    for(int i=0; i<s; i++)
    combo.addItem(postList.get(i));
    col.setCellEditor(new DefaultCellEditor(combo));
    //Set up tool tips.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for post office Id list");
    col.setCellRenderer(renderer);
    //Set up tool tip for the mailName column header.
    TableCellRenderer headerRenderer = col.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the Post Office Id to see a list of choices");
    }

  • Regarding inserting a field or text in template cell

    Hi Experts,
    Please let me know how to insert a field or text in the Cell in template.
    I created  template
    C1     1     14                             20.00     MM     8.00     CM     4.00   CM 4.00     CM                CM
    i have 14 lines and 3 columns in it
    i need to insert the feilds and text in it.
    Please let me know ,how to proceed.
    Thanks in advance.
    regards
    Vishnu

    Hi,
    To insert the text and field value inside the template you need to add insert the text inside the tempate node.
    assign the text or field into the text and then decide the position of the ext in the templete in output condition tab or text.
    insert the row and column number in the this to filed where you want to display the text.
    for e.g if field needs to displayed in the 2nd row and 3rd column then mention line = 2 and column = 3 in the output tab of the text.

  • Update jtable cell via numeric keypad

    Hi,
    I have a problem, trying to figure out how to input numbers in a jtextfield in a jtable cell, from a group of jbuttons (rendered as a numeric keypad). I can get the cell to focus, but when I click on one of the jbuttons in the keypad, the cell loses focus and nothing is printed. I can update the cell by directly typing from the keyboard; that works fine. But I'm lost when trying to do it from the touch-screen keypad. Can anyone point me in the right direction. I assume I need to attach additional listeners somewhere.
    Thanks in-advance.
    Lee

    I can get the cell to focus, Then the code for you button would need to be something like:
    String text = (String)table.getValueAt(...);
    String updated = text + button.getText();
    table.setValueAt(updated, ...);

Maybe you are looking for

  • Where do we put authorised user name for approving DMS document in DMS work

    HI I am on a support role and here is a document creation through DMS and it goes approval for 4 level , upon each level mail trigger to the user id (approval authorised person) . now company changed the users for approving authority , so i have to c

  • Single DB hit for Report Publication

    We have some Crystal Reports and Webi Reports Each Report we need to distribute to the end users in PDF/Excel Format. For Each reports the users >10000 members  Currently we are generating the reports trough publications . We have implemented role ba

  • Starting the DAC Server

    Hi All, For installing OBIA 11g i have installed OBIEE 111g and DAC 11g. While staring DAC server using startserver.bat file i am getting error like windows cannot find '-server'.Make sure typed name correctly, and then try againAnd startserver.bat f

  • 5142 rexplore

    Hello   I want to acquire real data only using 5142 I have mention the path through  which options I want to acquire the real data (attachment) include Real acq, real_frequency translation. What should be the options I have to set for this.  The vi's

  • Why are extensions hidden in firefox 10?

    no extensions showing in firefox 10