JTable's multiLine problem!!!

I want to use JTextArea as table's editor,but,there are only JtextFiled,JComboBox,Jcheckbox in DefaultCellEditor class ,there is not JTextArea,How to do?please help me!!!thanks!!!

HI Use this example..
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class JTextAreaTableExample extends JFrame
public JTextAreaTableExample()
super( "JTextAreaTableExample Example" );
DefaultTableModel dtm = new DefaultTableModel()
// make first cell uneditable
public boolean isCellEditable(int row, int column)
return !(column == 0);
dtm.setDataVector(new Object[][]{{ "JTextArea1", "This is a test\non long lines\n" },
{ "JTextArea2", "Hello, world!" }},
new Object[]{ "String","JTextArea"});
JTable table = new JTable(dtm);
table.getColumn("JTextArea").setCellRenderer(new TextAreaRenderer());
table.getColumn("JTextArea").setCellEditor(new TextAreaEditor());
table.setRowHeight(80);
JScrollPane scroll = new JScrollPane(table);
getContentPane().add(scroll);
setSize( 400, 250 );
setVisible(true);
public static void main(String[] args) {
JTextAreaTableExample frame = new JTextAreaTableExample();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
class TextAreaRenderer extends JScrollPane implements TableCellRenderer
JTextArea textarea;
public TextAreaRenderer()
textarea = new JTextArea();
textarea.setLineWrap(true);
textarea.setWrapStyleWord(true);
textarea.setBorder(new TitledBorder("This is a JTextArea"));
getViewport().add(textarea);
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column)
if (isSelected)
setForeground(table.getSelectionForeground());
setBackground(table.getSelectionBackground());
textarea.setForeground(table.getSelectionForeground());
textarea.setBackground(table.getSelectionBackground());
else
setForeground(table.getForeground());
setBackground(table.getBackground());
textarea.setForeground(table.getForeground());
textarea.setBackground(table.getBackground());
textarea.setText((String) value);
textarea.setCaretPosition(0);
return this;
class TextAreaEditor extends DefaultCellEditor
protected JScrollPane scrollpane;
protected JTextArea textarea;
public TextAreaEditor()
super(new JCheckBox());
scrollpane = new JScrollPane();
textarea = new JTextArea();
textarea.setLineWrap(true);
textarea.setWrapStyleWord(true);
textarea.setBorder(new TitledBorder("This is a JTextArea"));
scrollpane.getViewport().add(textarea);
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column)
textarea.setText((String) value);
return scrollpane;
public Object getCellEditorValue()
System.out.println("value :"+(String) textarea.getText());
return textarea.getText();

Similar Messages

  • JTable - Groupable/Multiline Header

    Hi Everybody,
    I found this code to create a groupable/multiline header for a JTable. It seems to be working fine with JDK 1.1 and we are using 1.4 now. I keep getting 2 errors with the GroupableTableHeaderUI class and has been busy the whole weekend trying to fix it, with no success. Can someone please help? Thanks. Here is the code:
    * |-----------------------------------------------------|
    * | | Name | Language |
    * | |-----------------|--------------------------|
    * | SNo. | | | | Others |
    * | | 1 | 2 | Native |-----------------|
    * | | | | | 2 | 3 |
    * |-----------------------------------------------------|
    * | | | | | | |
    package tableheader;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import swing.table.*;
    public class GroupableHeaderExample extends JFrame {
    GroupableHeaderExample() {
    super( "Groupable Header Example" );
    DefaultTableModel dm = new DefaultTableModel();
    dm.setDataVector(new Object[][]{
    {"119","foo","bar","ja","ko","zh"},
    {"911","bar","foo","en","fr","pt"}},
    new Object[]{"SNo.","1","2","Native","2","3"});
    JTable table = new JTable( dm ) {
    protected JTableHeader createDefaultTableHeader() {
         return new GroupableTableHeader(columnModel);
    TableColumnModel cm = table.getColumnModel();
    ColumnGroup g_name = new ColumnGroup("Name");
    g_name.add(cm.getColumn(1));
    g_name.add(cm.getColumn(2));
    ColumnGroup g_lang = new ColumnGroup("Language");
    g_lang.add(cm.getColumn(3));
    ColumnGroup g_other = new ColumnGroup("Others");
    g_other.add(cm.getColumn(4));
    g_other.add(cm.getColumn(5));
    g_lang.add(g_other);
    GroupableTableHeader header = (GroupableTableHeader)table.getTableHeader();
    header.addColumnGroup(g_name);
    header.addColumnGroup(g_lang);
    JScrollPane scroll = new JScrollPane( table );
    getContentPane().add( scroll );
    setSize( 400, 120 );
    public static void main(String[] args) {
    GroupableHeaderExample frame = new GroupableHeaderExample();
    frame.addWindowListener( new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
         System.exit(0);
    frame.setVisible(true);
    package swing.table;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class GroupableTableHeader extends JTableHeader {
    private static final String uiClassID = "GroupableTableHeaderUI";
    protected Vector columnGroups = null;
    public GroupableTableHeader(TableColumnModel model) {
    super(model);
    setUI(new GroupableTableHeaderUI());
    setReorderingAllowed(false);
    public void setReorderingAllowed(boolean b) {
    reorderingAllowed = false;
    public void addColumnGroup(ColumnGroup g) {
    if (columnGroups == null) {
    columnGroups = new Vector();
    columnGroups.addElement(g);
    public Enumeration getColumnGroups(TableColumn col) {
    if (columnGroups == null) return null;
    Enumeration enum = columnGroups.elements();
    while (enum.hasMoreElements()) {
    ColumnGroup cGroup = (ColumnGroup)enum.nextElement();
    Vector v_ret = (Vector)cGroup.getColumnGroups(col,new Vector());
    if (v_ret != null) {
         return v_ret.elements();
    return null;
    public void setColumnMargin() {
    if (columnGroups == null) return;
    int columnMargin = getColumnModel().getColumnMargin();
    Enumeration enum = columnGroups.elements();
    while (enum.hasMoreElements()) {
    ColumnGroup cGroup = (ColumnGroup)enum.nextElement();
    cGroup.setColumnMargin(columnMargin);
    package swing.table;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.plaf.basic.*;
    public class GroupableTableHeaderUI extends BasicTableHeaderUI {
    public void paint(Graphics g, JComponent c) {
    Rectangle clipBounds = g.getClipBounds();
    if (header.getColumnModel() == null) return;
    ((GroupableTableHeader)header).setColumnMargin();
    int column = 0;
    Dimension size = header.getSize();
    Rectangle cellRect = new Rectangle(0, 0, size.width, size.height);
    Hashtable h = new Hashtable();
    int columnMargin = header.getColumnModel().getColumnMargin();
    Enumeration enumeration = header.getColumnModel().getColumns();
    while (enumeration.hasMoreElements()) {
    cellRect.height = size.height;
    cellRect.y = 0;
    TableColumn aColumn = (TableColumn)enumeration.nextElement();
    Enumeration cGroups = ((GroupableTableHeader)header).getColumnGroups(aColumn);
    if (cGroups != null) {
    int groupHeight = 0;
    while (cGroups.hasMoreElements()) {
    ColumnGroup cGroup = (ColumnGroup)cGroups.nextElement();
    Rectangle groupRect = (Rectangle)h.get(cGroup);
    if (groupRect == null) {
    groupRect = new Rectangle(cellRect);
    Dimension d = cGroup.getSize(header.getTable());
    groupRect.width = d.width;
    groupRect.height = d.height;
    h.put(cGroup, groupRect);
    paintCell(g, groupRect, cGroup);
    groupHeight += groupRect.height;
    cellRect.height = size.height - groupHeight;
    cellRect.y = groupHeight;
    cellRect.width = aColumn.getWidth() + columnMargin;
    if (cellRect.intersects(clipBounds)) {
    paintCell(g, cellRect, column);
    cellRect.x += cellRect.width;
    column++;
    private void paintCell(Graphics g, Rectangle cellRect, int columnIndex) {
    TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    Component component = renderer.getTableCellRendererComponent(
    header.getTable(), aColumn.getHeaderValue(),false, false, -1, columnIndex);
    rendererPane.add(component);
    rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y,
                        cellRect.width, cellRect.height, true);
    private void paintCell(Graphics g, Rectangle cellRect,ColumnGroup cGroup) {
    TableCellRenderer renderer = cGroup.getHeaderRenderer();
    Component component = renderer.getTableCellRendererComponent(
    header.getTable(), cGroup.getHeaderValue(),false, false, -1, -1);
    rendererPane.add(component);
    rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y,
                        cellRect.width, cellRect.height, true);
    private int getHeaderHeight() {
    int height = 0;
    TableColumnModel columnModel = header.getColumnModel();
    for(int column = 0; column < columnModel.getColumnCount(); column++) {
    TableColumn aColumn = columnModel.getColumn(column);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    Component comp = renderer.getTableCellRendererComponent(
    header.getTable(), aColumn.getHeaderValue(), false, false,-1, column);
    int cHeight = comp.getPreferredSize().height;
    Enumeration enum = ((GroupableTableHeader)header).getColumnGroups(aColumn);
    if (enum != null) {
    while (enum.hasMoreElements()) {
    ColumnGroup cGroup = (ColumnGroup)enum.nextElement();
    cHeight += cGroup.getSize(header.getTable()).height;
    height = Math.max(height, cHeight);
    return height;
    private Dimension createHeaderSize(long width) {
    TableColumnModel columnModel = header.getColumnModel();
    width += columnModel.getColumnMargin() * columnModel.getColumnCount();
    if (width > Integer.MAX_VALUE) {
    width = Integer.MAX_VALUE;
    return new Dimension((int)width, getHeaderHeight());
    public Dimension getPreferredSize(JComponent c) {
    long width = 0;
    Enumeration enumeration = header.getColumnModel().getColumns();
    while (enumeration.hasMoreElements()) {
    TableColumn aColumn = (TableColumn)enumeration.nextElement();
    width = width + aColumn.getPreferredWidth();
    return createHeaderSize(width);
    package swing.table;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class ColumnGroup {
    protected TableCellRenderer renderer;
    protected Vector v;
    protected String text;
    protected int margin=0;
    public ColumnGroup(String text) {
    this(null,text);
    public ColumnGroup(TableCellRenderer renderer,String text) {
    if (renderer == null) {
    this.renderer = new DefaultTableCellRenderer() {
         public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
         JTableHeader header = table.getTableHeader();
         if (header != null) {
         setForeground(header.getForeground());
         setBackground(header.getBackground());
         setFont(header.getFont());
    setHorizontalAlignment(JLabel.CENTER);
    setText((value == null) ? "" : value.toString());
         setBorder(UIManager.getBorder("TableHeader.cellBorder"));
         return this;
    } else {
    this.renderer = renderer;
    this.text = text;
    v = new Vector();
    * @param obj TableColumn or ColumnGroup
    public void add(Object obj) {
    if (obj == null) { return; }
    v.addElement(obj);
    * @param c TableColumn
    * @param v ColumnGroups
    public Vector getColumnGroups(TableColumn c, Vector g) {
    g.addElement(this);
    if (v.contains(c)) return g;
    Enumeration enum = v.elements();
    while (enum.hasMoreElements()) {
    Object obj = enum.nextElement();
    if (obj instanceof ColumnGroup) {
    Vector groups =
    (Vector)((ColumnGroup)obj).getColumnGroups(c,(Vector)g.clone());
    if (groups != null) return groups;
    return null;
    public TableCellRenderer getHeaderRenderer() {
    return renderer;
    public void setHeaderRenderer(TableCellRenderer renderer) {
    if (renderer != null) {
    this.renderer = renderer;
    public Object getHeaderValue() {
    return text;
    public Dimension getSize(JTable table) {
    Component comp = renderer.getTableCellRendererComponent(
    table, getHeaderValue(), false, false,-1, -1);
    int height = comp.getPreferredSize().height;
    int width = 0;
    Enumeration enum = v.elements();
    while (enum.hasMoreElements()) {
    Object obj = enum.nextElement();
    if (obj instanceof TableColumn) {
    TableColumn aColumn = (TableColumn)obj;
    width += aColumn.getWidth();
    width += margin;
    } else {
    width += ((ColumnGroup)obj).getSize(table).width;
    return new Dimension(width, height);
    public void setColumnMargin(int margin) {
    this.margin = margin;
    Enumeration enum = v.elements();
    while (enum.hasMoreElements()) {
    Object obj = enum.nextElement();
    if (obj instanceof ColumnGroup) {
    ((ColumnGroup)obj).setColumnMargin(margin);

    in GroupableTableHeaderUI class replace "aColumn.getHeaderRenderer();" by "header.getDefaultRenderer ();" and try again..
    this should solve ur problem ..
    Indranil

  • JTable horizontal scrollbars problems.

    When I create JTable component with colons that width more than ScrollPane object one, no horizontal bar is created and all colomns shrank so i can't view what is written in cells.
    If somebody know why horizontal bar is not created?
    Some problem with ScrollPane or I need do some trics?
    Thanx:))

    JPanel contentPane;
    XYLayout xYLayout1 = new XYLayout();
    JScrollPane jScrollPane1 = new JScrollPane();
    String[] cols = {"Name", "Type", "Weignt", "Height", "EyaColor", "EyaSkin"};
    String[][] rows = {{"dklfgjfghjfdjfghj","dkffghjfghjfgjjjd","dkffghjfghjfgjjjd,h,ffgdf","dfgdlhjklhjkhjlfgdfg","dfghjlhjlhjkhgjkdfg","dfghdfhgjklhjkgfkgfhjhdfgh"},
    {"dklfgjfghjfdjfghj","dkffghjfghjfgjjjd","dfgffgdf","dfgdfgdfg","dfgdfg","dfghdfhdfgh"},
    {"dklfgjfghjfdjfghj","dkffghjfghjfgjjjd","dfgffgdf","dfgdfgdfg","dfgdfg","dfghdfhdfgh"},
    JTable jTable1 = new JTable(rows,cols);
    //setIconImage(Toolkit.getDefaultToolkit().createImage(TestTableFrame.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(xYLayout1);
    this.setSize(new Dimension(639, 339));
    this.setTitle("Test Table");
    contentPane.add(jScrollPane1, new XYConstraints(21, 29, 570, 279));
    jScrollPane1.getViewport().add(jTable1, null);

  • JTable data persistance problem

    i have large number of rows to be displayed in a JTable , the user can configure the number of rows he
    wants to view , the table will have next and previous buttonns to navigate to the different pages , i have
    solved the problem by reading data from. a 2 dimensional object array according to the user choice , the
    next and the previous buttons are working , but the problem is there is no data persistance for example if
    the user deletes 2 rows from the 1st page and goes to the 2nd page , when he comes back again to the 1st
    page the deleted elements are still there. I am using an my own model which implements abstract table model.It would b gr8 if any one can send the code.Thanks in advance.

    Are you removing the rows from your Object Array?
    if so, you are rigth now, you must to use at you model
            fireTableDataChanged();When you change data from your object array.
    Hope this helps...

  • Help!!! JTable cell editor problem...

    I am having a problem with table cell editors.
    The problem is that when I click on another component
    in the frame (out side of the JTable) the cell editors's
    stopCellEditing() is not called so I get a JTable with a cell
    editor in editing mode.
    Any help?
    Thanks a lot

    It is difficult to tell what happens with FocusEvents when you are actually editing a cell and the editor is "up". I am experiencing different difficulties with the same root issue. I think the problem here is that the Java Focus Manager is consuming the focus event without propagating the event to any of the JTable components (CellEditor or JTable). I am not sure if this is exactly the case but I haven't been able to trap focus events in the Editors, Renderers or JTable anywhere. If the editor is not "up" then event handling seems to be fairly normal but when you are actually editing a cell it becomes tricky.
    However, this is a problem I fixed by placing a FocusGained event handler on the other (non JTable) component and then manually stopping editing on the JTable. In other words in the JFrame (or whatever component you are using) I added a FocusListener to the non JTable component and inside of FocusGanied() I execute:
    public void focusGained(FocusEvent e){
    table.getCellEditor().stopEditing();
    table.removeEditor();
    You could, of course, use cancelEditing() as well. You'll probably want to wrap the code with some robustness as follows to ensure that you don't get trapped by wierdness.
    public void focusGained(FocusEvent e){
    if (table.isEditing() && table.getCellEditor() != null){
    table.getCellEditor().stopEditing();
    table.removeEditor();
    This is probably not the only way to solve the problem but it was the way that worked when I encountered that issue.

  • Custom JTable cell editor problem

    I have a custom JTable cell editor which is a JPanel with 2 JtextFields, One for a name, the other for a data value. My problem lies in when the the cell is selected and then the user start typing. The JTextfield outline shows up, but there is no carat. I can only edit the cell when I click the mouse in it again. I have my isCellEditable method set to only allow editing on 2 mouse clicks, but I did try it with just returning true and had the same problem. Please help.
    Code:
    class cellValue {
    String name;
    String data;
    Color nameColor;
    Color dataColor;
    Font font;
    public cellValue(String n, String d, Color nC, Color dC, Font ff){
    name = n;
    data = d;
    nameColor = nC;
    dataColor = dC;
    font = ff;
    } //end class
    public class TextFieldCellEditor extends JPanel implements TableCellRenderer, TableCellEditor{
    private EventListenerList listenerList = new EventListenerList();
    private ChangeEvent event = new ChangeEvent(this);
    private cellValue s;
    private int e_row=0;
    private int e_col=0;
    private JTextField ta;
    private JTextField tb;
    public TextFieldCellEditor() {
    setLayout(new GridBagLayout());
    ta = new JTextField();
    tb = new JTextField();
    tb.setHorizontalAlignment(SwingConstants.RIGHT);
    add(ta, new GridBagConstraints(0,0,1,1,0.6,0.0,java.awt.GridBagConstraints.WEST,java.awt.GridBagConstraints.BOTH,new Insets(0,1,0,0),0,0));
    add(new JLabel(" "),new GridBagConstraints(1,0,1,1,0.1,0.0,java.awt.GridBagConstraints.WEST,java.awt.GridBagConstraints.BOTH,new Insets(0,1,0,0),0,0));
    add(tb, new GridBagConstraints(2,0,1,1,0.3,0.0,java.awt.GridBagConstraints.EAST,java.awt.GridBagConstraints.BOTH,new Insets(0,1,0,0),0,0));
    } //end init
    public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected,
    boolean hasFocus,int row, int column) {
    s = (cellValue)value;
    e_row = row;
    e_col = column;
    ta.setText(s.name);
    tb.setText(s.data);
    ta.setFont(s.font);
    tb.setFont(s.font);
    ta.setForeground(s.nameColor);
    tb.setForeground(s.dataColor);
    setForeground(table.getForeground());
    setBackground(table.getBackground());
    ta.setBackground(table.getBackground());
    tb.setBackground(table.getBackground());
    ta.setCaretColor(Color.WHITE);
    tb.setCaretColor(Color.WHITE);
    return (JComponent)(this);
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    return (getTableCellRendererComponent(table, value,isSelected, true, row, column));
    public boolean isCellEditable(EventObject e) {
    if (e instanceof MouseEvent) {
    return ((MouseEvent)e).getClickCount() >= 2;
    } return true;
    // return true;
    public boolean shouldSelectCell(EventObject anEvent) {
    return (true);
    public void cancelCellEditing() {
    public boolean stopCellEditing() {
    fireEditingStopped();
    return (true);
    public Object getCellEditorValue() {
    return (ta.getText());
    public void addCellEditorListener(CellEditorListener l){
    try {
    SwingUtilities.invokeLater(
    new Runnable() {
    public void run() {requestFocus();}
    } catch (Exception e) {};
    listenerList.add(CellEditorListener.class, l);
    public void removeCellEditorListener(CellEditorListener l) {
    listenerList.remove(CellEditorListener.class, l);
    protected void fireEditingStopped(){
    Object[] listeners = listenerList.getListenerList();
    for (int i = listeners.length - 2; i >= 0; i -= 2)
    ((CellEditorListener)listeners[i+1]).editingStopped(event);
    protected void fireEditingCanceled() {
    Object[] listeners = listenerList.getListenerList();
    for (int i = listeners.length - 2; i >= 0; i -= 2)
    ((CellEditorListener)listeners[i+1]).editingCanceled(event);
    } //end class

    Thanks again for the repley.
    I tried removing the celleditorlistener and using the setSurrenderFocusOnKeystroke, but it did not work. The textfield is editable;
    I did change:
    public void addCellEditorListener(CellEditorListener l){
    try {
    SwingUtilities.invokeLater(
    new Runnable() {
    public void run() {ta.requestFocus();}
    } catch (Exception e) {};
    listenerList.add(CellEditorListener.class, l);
    }This allows the first textfield to request focus and this seems to work. But when I highlight a cell, then start typing, the first character I type puts me into the editor, but it is lost. Example:
    I type hello
    and get ello in the cell. Then when I press enter the input is excepted and the selection goes to the next cell, but I cannot move the Highlight cursor at all, seems locked. The only way I can continue to the next cell is to use the mouse.
    You said you had a cell editor working. Would you care to share as an example. This is killing me to get this to work properly.
    Thanks again
    Dave

  • JTable Cell Editor Problems

    Hi All,
    I have a problem concerning the editing for my table. When I click on a column a dialog box opens up and the user picks the values he wants. But after he presses ok in the dialog box the user again has to press enter in the selected cell or click on another cell in the table for the selected cell to lose focus.I am using a textfield as the returning component in the getcomponent method for the the table cell editor. Is there a way I can force the textfield to register an enter automatically so it loses focus or is there another way?
    Thanks, in advance.

    this is how my code is structured:
    public class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor,
         ActionListener{
         private static final long serialVersionUID = 0;
         private int clickCountToStart = 2; // Default value is double click
         private JFrame editingFrame;
         // This is the component that will handle the editing of the cell value
         JTextField txtresult = new JTextField(10);
         String result = null;
         public MyTableCellEditor(JFrame jframe){
              //txtresult.addActionListener(this);       
              editingFrame = jframe;
        public int getClickCountToStart(){
            return clickCountToStart;
        public int setClickCountToStart(int c){
            clickCountToStart = c;
             return clickCountToStart;
        public boolean isCellEditable(EventObject e){
            if(e instanceof MouseEvent){
                 if(((MouseEvent)e).getClickCount()>=this.getClickCountToStart()){
                      return true;
            return false;
        public boolean stopCellEditing(){
             fireEditingStopped();
             return true;
        // This method is called when a cell value is edited by the user.
        public Component getTableCellEditorComponent(JTable table, Object value,
                boolean isSelected, int row, int col) {
             // Make certain columns non editable
             if(table.getColumnName(col).equals("Sub Number")){
                  return null;
             else if(table.getColumnName(col).equals("Transmitter#/Receiver#")){
                  return null;
             if(table.getColumnName(col).equals("TOOLMODE")){
                  result = toolModeModify();
                 if(result==null){
                      result = value.toString();
                  if(result != null){
                      txtresult.setText(result);
                 else{
                      txtresult.setText(value.toString());
            else{
                 result = ModifyCell();
                 if(result != null){
                      txtresult.setText(result);
                 else{
                      if(value != null){
                           txtresult.setText(value.toString());
             txtresult.setEditable(false);
             return txtresult;
        public void actionPerformed(ActionEvent e) {
            //stopCellEditing(); //Make the renderer reappear.
        // This method is called when editing is completed.
        // It must return the new value to be stored in the cell.
        public Object getCellEditorValue() {
             try{
                 return txtresult.getText();
             }catch(NullPointerException ne){
                  return null;
        private String toolModeModify(){
             Object[] possibilities = {"0", "1", "2","3"};
             String number = (String)JOptionPane.showInputDialog(
                                 editingFrame,
                                 "Option 0: Receiver\n"
                                 + "Option 1: UDT\n"
                                 + "Option 2: TRX/UDR\n" +
                                 "Option 3: OFF\n",
                                 "Select Mode",
                                 JOptionPane.PLAIN_MESSAGE,
                                 null,
                                 possibilities,
                                 "0");
             return number;
        private String ModifyCell(){
              String editCell = "Edit Cell Value";
              String s;
              s = JOptionPane.showInputDialog(editingFrame, editCell, null,
                        JOptionPane.PLAIN_MESSAGE);
              if(s != null){
                   return s;
              else{
                   return null;
    }I dont know what I am doing wrong.

  • JTable cell editor problem

    Hi, I have a custom cell editor component being used on my JTable (a calendar component) and am having problems bringing the component out of edit mode when selecting another cell.
    If I click on a cell it enters edit mode correctly, the I can drop a popup window out from this editor to display the calendar. If however I move to another cell this window remains active.
    Could anyone explain how to come out of edit mode when moving to another cell (not necessarily selecting just moving the mouse in to another) ?
    I also have a second problem in that the calendar editor doesn't set the value in to the cell when choosing a date from the component. It keeps the original value that was in the cell. I have implemented a setValueAt() method so I'm not sure why this is not fired, any ideas?? Code is below :
    public class DueDateTableModel extends AbstractTableModel {
        private Vector vAllDueDates = null;
        private Connection conn = null;
        private Statement stmt = null;
        private ResultSet rsDueDates = null;
        private int iColCount;
        private String sSqlDueDates = null;
        private String[] testColNames = null;
        public DueDateTableModel(int pColCount, Vector pAllDueDates, String[] pColNames){
            iColCount = pColCount;
            vAllDueDates = pAllDueDates;
            testColNames = pColNames;
            populateTableCells();
            //setupEditors();
        public int getColumnCount() {
            return iColCount;
        public int getRowCount() {
            return vAllDueDates.size();
        public String getColumnName(int iCol) {
              return testColNames[iCol];
        public Object getValueAt(int iRow, int iCol) {
            // TODO Auto-generated method stub
            Vector v = (Vector)vAllDueDates.elementAt(iRow);
            return v.elementAt(iCol);
        public void setValueAt(Object oValue, int iRow, int iCol) {
            Vector v = (Vector)vAllDueDates.elementAt(iRow);
            v.setElementAt(oValue,iCol);
            fireTableCellUpdated(iRow,iCol);
        public boolean isCellEditable(int iRow, int iCol) {
            if(getValueAt(iRow,iCol)==null){
                return false;
            }else{
                return true;
        private class DueDateEditor extends CalendarComboBox implements TableCellEditor{
            //protected EventListenerList listenerList = new EventListenerList();
            //protected ChangeEvent changeEvent = new ChangeEvent(this);
            public DueDateEditor(){
                super();
            public void removeCellEditorListener(CellEditorListener l){
                //listenerList.remove(CellEditorListener.class, l);
            public Component getTableCellEditorComponent(JTable table, Object value
                    , boolean isSelected, int row, int column){
                //Just return the input panel and not the panel that the calendar comboBox is on
                return this.inputPanel;
              public Object getCellEditorValue(){
                  return this.getDate();
              public boolean isCellEditable(EventObject evt) {
                //if (evt instanceof MouseEvent) {
                  //  return ((MouseEvent)evt).getClickCount() >= 2;
                return true;
              public boolean shouldSelectCell(EventObject anEvent){
                  return false;
              public boolean stopCellEditing(){
                  //this.setDate();
                  return true;
              public void cancelCellEditing(){
              public void addCellEditorListener(CellEditorListener l){
                  //listenerList.add(CellEditorListener.class, l);
              /*protected void fireEditingStopped() {
                  CellEditorListener listener;
                  Object[] listeners = listenerList.getListenerList();
                   for (int i = 0; i < listeners.length; i++) {
                         if (listeners[i] == CellEditorListener.class) {
                                listener = (CellEditorListener) listeners[i + 1];
                                listener.editingStopped(changeEvent);
        }Sorry the classes are quite basic, I'm not very familiar with custom cell editors, I have normally used default ones like combobox etc.
    Regards
    Alan

    To get better help sooner, post a SSCCE that clearly demonstrates your problem.
    To post code, use the code tags -- [code]Your Code[/code]will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
    luck, db

  • JTable Cell RENDERER PROBLEM!!! PLEASE HELP

    I have been trying to code stuff with Java TableCellRenderer...here is my current code:
    private class DetailTableCellRenderer 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(row==0 && column==0)
    this.setBackground(Color.red);
    this.setHorizontalAlignment(CENTER);
    this.setHorizontalTextPosition(CENTER);
    return this;
    and in jbinit(), i have this line:
    DetailedTable.setDefaultRenderer(String.class,new
    DetailTableCellRenderer());
    *By the way, ive tried putting Color.class, JTable.class, JLabel.class, and just about everything else imaginible...nothing seems to work...
    my point is to center the text in a JTable and to customize the background color of certain cells...
    I have tried looking for this topic multiple times, but every time a piece of code is given, the code doesnt work...please offer suggestions...any are much appreciated...
    thanks,
    Sid

    I just scratched my previous answer because I went
    back and re-read your problem. By what you typed
    DetailedTable.setDefaultRenderer(String.class,newDetailTableCellRenderer());
    it seems you're trying to set the default renderer on
    the Class. You can't do that - you have to set
    the renderer on the instance of the class:
    DetailedTable t = new DetailedTable(); // assuming
    DetailedTable is a sub-class of
    // JTable (why,
    // JTable (why, I don't know)
    t.setDefaultRenderer(String.class,new
    DetailTableCellRenderer());If this is not the case and DetailedTable is
    the instance, then I've always done this:
    detailedTable.getColumn(cName).setCellRenderer(new
    DetailTableCellRenderer());
    Hi, thanks for the reply...detailedtable is an instance of JTable not a subclass...
    i have tried doing the getColumn(cName) before, but it also does not seem to work...when i do that with, say, column 0, i cant select anything in column 0 and it doesnt work anyway...also, if i want this feature for the whole table, should i have multiple calls to this getColumn function with different cNames?
    thanks...
    Sid

  • JTable cell render problem, help!

    Hi all,
    I'm trying to change the color of some cells in a JTable. I have the definition of what cell to render in a different color in a Vector. So each time the cell render is called, I check if the cell it's in my vector, and if yes I change the background color to red.
    The problem is, the result are not the desired, some cells are some times in red other times in red! Some one have an idea of what appends?
    Thanks NeuralC
    public Component getTableCellRendererComponentJTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component cell = super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column);
    for(int i=0;i<((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.size();i++){
    if(((column)>=((Gama)((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.elementAt(i)).inicio) & ((column) <=((Gama)((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.elementAt(i)).fim)){
    cell.setBackground(Color.red);
    return cell;
    cell.setBackground(Color.white);
    return cell;
    }

    Hi,
    AND symbol is &, and I must use it.
    I haved solved the problem, extending my cell render to a JLabel. With this and making my self the selection color everything works fine.
    Thanks for interrest.
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    JLabel lb = new JLabel((String)value);
    //Component cell = super..;
    setText((String)value);
    if(!isSelected){
    setBackground(Color.white);
    else{
    setBackground(Color.blue);
    for(int i=0;i<((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.size();i++){
    if(((column)>=((Gama)((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.elementAt(i)).inicio) & ((column) <=((Gama)((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.elementAt(i)).fim)){
    if(hasFocus){
    setToolTipText("est� dentro"+column);
    setBackground(Color.red);
    return this;

  • Jtable Horizontal ScrollBar problem

    Hi,
    I am having a Jtabel inside a JscrollPanel with horizontal and vertical scrollpane.
    My table model contains say 20 columns.But i am showing only 10 columns hiding the other 10.when i click on the table header i will show the rest of 10.so now the total columns are 20.but when i scroll thehorizantal bar to the see the other 10 coulmns the header for the latest 10 coulmns is not showing properly.
    Is there anybody to help me to sort out this problem.
    Thanks in advance.
    sree

    Hi,
    how ican saw Scrollbar with out Jtable.AUTO_RESIZR_OFF.That i already did.That not the actual problem.any how i solved this problem finally.It is something with TableHeaderRenderer..Any how thanks for ur help.
    sree

  • Java JTable Screen Blink Problem.

    Dear All,
    I am facing Screen blink issue while using the JTable.
    JTable is updated in real Time, It uses custom table model.
    To update the JTable, I update the Table Model and then call the UpdateUI() and repaint(). These update process is running in non-AWTevent-dispatch thread. So, During the real Time Update of the Table, When we do some rough handling work on the Table( for example, press the Enter Key on the Table for 1-2 minutes, move the Scroll Bar up and down fastly etc), It throws the following exception and the Table starts blinking.
    java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1141)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1051)
    at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:974)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
    at javax.swing.JComponent.paintComponent(JComponent.java:541)
    at javax.swing.JComponent.paint(JComponent.java:808)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    The blinking also moves to Other Components such as JTree which is doing real time update in another screen of the Same Application.
    How to resolve this Screen Blinking Phenemenon ? Some suggested to use SwingUtilities.invokeLater() for UpdateUI(). But, I am concerned about the performance, using it in real time update as it may create many threads, it may cause other performance issues. Is other any other better solution ?
    Looking forward to your comments !
    Thanks !

    To update the JTable, I update the Table Model and then call the UpdateUI() and repaint(). No need to call updateUI() (I'd like to shot the person in the forum who keeps suggesting that and shot the people who keep using the method without reading the API to see what it actually does) or repaint(). You simply update the TableModel and the table will repaint itself.
    Here is a simple example of real time updates to a table from a non-GUI thread:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=597870
    We can't help you because we have absolutely no idea what your code looks like

  • JTable with JCheckbox problems

    Ok so I have a couple of questions. I have a JTable with a column represented as a checkbox.
    1. If I put the checkbox column as the first in the table, the rest of the cells are blank/null. Any idea what the reason is?
    2. What is the best workaround to having draggable columns, meaning icons/checkboxes don't render if you move the columns around?
    3. Does anyone have some links to good resources on JTables and things like custom components in them. I have googled but don't get many good links so would appreciate any help
    Code snippet as follows:
    public class ClobberTableCellRenderer implements TableCellRenderer
    private JPanel renderPanel = new JPanel(new BorderLayout());
    private JLabel renderLbl = new JLabel("");
    private JCheckBox checked = new JCheckBox();
    private Icon successIcon;
    private Icon errorIcon;
    public Component getTableCellRendererComponent(JTable table,
    Object value,
    boolean isSelected,
    boolean hasFocus,
    int row,
    int column)
    String columnName = table.getModel().getColumnName(column);
    if (value == null)
    return null;
    else if ("Status".equals(columnName) && "ok".equals(value))
    renderLbl.setIcon(successIcon);
    renderLbl.setText("");
    renderPanel.remove(checked);
    else if ("Status".equals(columnName) && "error".equals(value))
    renderLbl.setIcon(errorIcon);
    renderLbl.setText("");
    renderPanel.remove(checked);
    else if ("Active".equals(columnName))
    renderLbl.setText("");
    renderPanel.add(checked);
    renderPanel.setBackground(Color.white);
    else
    renderLbl.setHorizontalAlignment(value instanceof Date || value instanceof Number ? JLabel.RIGHT : JLabel.LEFT);
    renderLbl.setIcon(null);
    renderLbl.setText(value instanceof Date ? df.format((Date)value) : value.toString());
    renderLbl.setToolTipText(null);
    renderPanel.setToolTipText(null);
    renderPanel.remove(checked);
    if (isSelected)
    renderPanel.setBackground((Color)UIManager.getDefaults().get("Table.selectionBackground"));
    else
    renderPanel.setBackground((Color)UIManager.getDefaults().get("Table.background"));
    return renderPanel;
    }

    Hi :) I have also worked on JTables and JCheckBoxes before. This article
    helped me a lot: http://www-128.ibm.com/developerworks/java/library/j-jtable/

  • Combobox in jtable two tab problem

    Hi all,
    If i am using combobox for one of the columns of jtable with custom editor and renderer, it needs two tab for navigation between the cells.
    How can i make it as 'one tab navigation'. Even i tried with 'isManagingfocus() return true' but...no effect.
    thanx in advance.
    S.A.Radha.

    here I'm giving a simple sample code. Refer this..
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.awt.*;
    public class Class1 extends JFrame {
    JScrollPane jScrollPane1 = new JScrollPane();
    JTable editableTable1 = new JTable(3, 3);     
    public Class1() {
    try {          
    JComboBox c = new JComboBox();
    c.setEditable(true);
    c.addItem("a");
    c.addItem("b");
    DefaultCellEditor cellEditor = new DefaultCellEditor(c);
    TableColumn tc = editableTable1.getColumnModel().getColumn(0);
    tc.setCellEditor(cellEditor);
    this.getContentPane().setLayout(null);
    jScrollPane1.setBounds(new Rectangle(25, 19, 330, 180));
    this.getContentPane().add(jScrollPane1, null);
    jScrollPane1.getViewport().add(editableTable1, null);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    System.exit(0);
    } catch(Exception e) {
    System.out.println("Exception in Class1:"+e);
    public static void main(String[] args) {
    Class1 class1 = new Class1();
    class1.setSize(400, 400);
    class1.setVisible(true);

  • BPM transformation multiline problem

    I have a transformation in an Integration Process. My Source Messages field points to a Multiline container element CollectDeliveries. My Target Messages field points to a non-multiline element SendShipment.
    When I check the Integration Process, I get a red frame around the Source Message field stating that:
    Expression must not return a multiline value.
    If I remove the Multiline checkbox value of the CollectDeliveries container, the error disappears, but my CollectDeliveries container contains multiple Deliveries, so it is conceptually correct.
    What could be going wrong here? Any clues?
    Kind Regards,
    Tony.

    Anthony,
    Check for your Interface mapping. It also must be Source 0..Unbounded and target 1..1.
    raj.

Maybe you are looking for

  • HOW TO DELETE DUPLICATE ELEMENT IN A VECTOR

    Hi everybody! If I've a vector like this vectA={apple,orange,grape,apple,apple,banana} and I want final result be vectB={apple,orange,grape,banana}. How should I compare each element in vectA and delete duplicate element. Like here duplicated element

  • Zen Micro isn't working on 2 computers out of th

    Hi everybody. Once I updated my zen micro player's firmware, it doesn't work on 2 computers out of 3. There doesn't seem to be any sort of conflict with the device. The Zen Micro works on my laptop that runs a windows xp HOME edition. This seems to b

  • Using 1099 MISC Reporting

    Hi Friends, Client is using ECC 6. We updated vendor master with 1099 information in witholding tax field, one month after we went live. Entries were posted in 1099 vendors, and it gave us warning message <b> "Postprocess open items after changing re

  • ITunes closed unexpected when using BeoSoundPlugin

    Hi, After installing iTunes 10 a few days ago I am not able to open my iTunes anymore. If I try to I get a "Problem report about iTunes" saying that iTunes closed unexpected when using BeoSoundPlugin. I have never experienced any problems with this b

  • ITunes crashing when trying to open "apps" folder when iPhone is connected.

    When I plug in my iPhone and try to open the "apps" folder, itunes crashes. This problem occurs everytime I try to open the "apps" folder. Please help?