Multi TextArea cell of JTable

Hi, I am developing a timetable tool. Some time there are more one
event in one timeslot (cell). Therefore, I have to display those events vertically
in a cell, and each of those needs to be recongised by a mouse click. I plan to use multi textAreas
that attached to a panel in the cell. I am not sure how to do this.
I am thinking to create a class implement both a renderer and an editor.
The method getTableCellEditorComponent() would return a JPanel or something like that, and the panel would contain components (like JTextArea). But now sure how it works.
Please help.

This will give you an idea...
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

Similar Messages

  • Aligning the Text in Centre for MultiLine Cells in JTable

    Hi;
    Does anyone know how I could make a java table that has multiline text cells AND this multiline text is aligned to center? I tried to extend JTextArea and to implement TableRenderer - multiline was OK but it did not do anything on setHorizontalAlign. If I extend DefaultTableRender than I can align the text to center but I got no multiline...
    Any ideas?
    Kindly to provide me a solution for this its urgent.

    Hi;
    Thanks for the reply,on using Text Area as renderer i.e using Multi-Line cells in JTable, i achieved the objective of displaying the text on multiple lines in the cell."In my Table there are 5 columns and i'm setting renderer on 3rd and 5th column,If the text is too large in column 5 it automatically gets wrapped off for all the cells in column 5.For column 3 my text is not so large as compared to column 5 and due to which the Text in the column 3 starts from the top for all the cells i.e (the first row in column 3 is parallel to first row in column 5 ),Now the problem is i can't display the text in the center of all cells for Column 3 .
    Thanks in advance

  • JTable Multi-Span Cell Example

    Searched the Forum und Google for the "JTable Multi-Span Cell Example" and always found this Link :
    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    But the Examples are only working with JDK 1.3.1, JDK 1.4.1 and JDK 1.4.2 aren`t working anymore.
    What do i have to change, or are there any new examples for Multi-Span Cells in the JTable provided by SUN ?

    In AttributiveTableCellModel.java, rewrite the following function:
    public void setDataVector(Vector newData, Vector columnNames) {
    if (newData == null)
    throw new IllegalArgumentException("setDataVector() - Null parameter");
    dataVector = new Vector(0);
    setColumnIdentifiers(columnNames);
    dataVector = newData;
    super.setDataVector(newData, columnNames);
    cellAtt = new DefaultCellAttribute(newData.size(),
    columnIdentifiers.size());
    newRowsAdded(new TableModelEvent(this, 0, getRowCount()-1,
              TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
    }

  • Align for multi-header renderer in JTable

    Hi,
    I have a question about multi-header renderer in JTable. Here is the problem, please help me:
    I used the MultiLineHeaderRenderer class example from
    http://www2.gol.com/users/tame/swing/examples/JTableExamples1.html
    This example makes the header to be centered (as setHorizontalAlignment(JLabel.CENTER)). Also, it is for the all the headers with 2 lines (i don't know how to describe it).
    In my project, I have just a few header with 2 lines, most of them are one line. By using this example renderer class, I have the header height is bigger, of course because of some 2 lines headers, and one line header is automatically set as the TOP. What I want is to make one line header to be set as the BOTTOM just like in EXCEL.
    Please help me, sorry for my technical explaination (poor huh?)
    Thanks in advance.

    If I understand correctly just put a space then a new line before your text for your cell that you want the text at the bottom.
    like this: " \nBottom Text"
    You'll need the leading space because of how StringTokenizer works.

  • How to change the Background color of a cell in JTable

    hi!
    Actually i want to change the background color of few cells in JTable
    is there any method to make this change in JTable ?
    and also is it possible to have 5 rows with single column and 5 rows with 3 columns in a single JTable

    i want to change the background color of few cells in JTableDepending on your requirements for the coloring of cells it may be easier to override the prepareRenderer() method of JTable:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

  • Change the background color of a cell in JTable

    Hi all,
    How can I change the background color of individual cell in JTable. I need to construct my own TableCellRenderer or not? I'm now using the DefaultTableCellRenderer now.
    Thx

    You could create your own renderer or you could try something like:
    table = new JTable(model)
         public TableCellRenderer getCellRenderer(int row, int column)
              DefaultTableCellRenderer tcr =
               (DefaultTableCellRenderer)super.getCellRenderer(row, column);
              if (row == 1 && column == 1)
                   tcr.setBackground(Color.green);
              else
                   tcr.setBackground(Color.red);
              return tcr;
    };

  • How can I get right data in a cell of JTable when table  enter editing

    how can I get right data in a cell of JTable when table enter editing

    how can I get right data in a cell of JTable when table enter editing

  • Setting Focus to a particular cell in JTable

    Hi, can i know how to set the focus to a particular cell in JTable.
    Say I have a table with 2 rows and 10 columns. The focus now is at position (1, 9) which is the last cell in the table. But I want to set the focus to (1, 3). How can i achieve this ? Pls help. Thanks

    OK. It's partially working. The right methods to use are setRowSelectionInterval and setColumnSelectionInterval. Jeanette was right. Mine didn't work because of a thread issue. I put the those two methods in a block such as:
    SwingUtilities.invokeLater(new Runnable(){
    public void run()
    table.setRowSelectionInterval(tblLineItem.getRowCount()-1,
    table.getRowCount()-1);
    table.setColumnSelectionInterval(0,0);
    Then it worked.
    But after I finished editing the first cell of the newly created row and press ENTER, the selection went back to the cell that's next to the originally editing cell on the first(old) row, instead of staying at the current row and going to the second cell.
    Can anybody shed a light on what I'm missing?

  • How to disable a particular cell in JTable ?

    I having a problem on how to set disable a particular cell in JTable. At the first place to load the JTable, I want to set some of the cell to disabled, it only will run at the first time, is there anyway to do it ?

    This is the function that disable/enable cells in JTables.
    Are you looking for this?
    public boolean isCellEditable(int row, int col)
      if(((new Integer((String)(getValueAt(row,0)).toString()).intValue()>9))&&(col==1))
        return true;
      if(row!=4&&col!=5)
        return true;
      return false;
         this metod belong to the TableModel function
    and what I gave you is only an example of what you can do with it.
    if it return false it disable and if true it enable the cell...but I think this you allready know!
    Regards Amnon

  • Append table with multi-line cells to word report

    Hi,
    I am using LabView 7.0. I need to append table to word report and I am using Append Table to Report VI. My VI works fine as long as the table cells do not have multiple lines. For multiple lines, each line is put is a seperate cell in the word report.
    Is there a way to append multi-line cells to Word Report??? If not, any suggestions on how I can copy the multi-line table to Word report???
    Please kindly help!!
    Please see the attached document for details on the problem.
    Thanks,
    Mim
    Attachments:
    Table with multiple line cells.doc ‏33 KB

    Hi Mim,
    Yes I understood the multiple-lines part. I think the doc is the report you want. Correct ?
    The doc is generated with your VI without any modifications.
    I am using XP, Office 2002 SP3 and LV7.1
    Attachments:
    Verification Report.doc ‏39 KB

  • Unable to edit cells in JTable on single click of the cell.

    Hi,
    I am unable to edit a cell in JTable on single click of the cell. If I double click on the cell, I am able to edit it. Please help me.
    Thanks
    Subbu

    Thanks for all replies. Now, i am able to edit the cell on single click.

  • What component is placed default in each cell of JTable?

    Hi,
    What component is placed default in each cell of JTable?

    It depends on the content, see How to Use Tables - Concepts: Editors and Renderers for details.

  • Problem with select all cells in JTable

    Hi guys! I get some problem about selecting all cells in JTable. I tried to used two methods:
    1> table.selectAll()2> changeSelection(firstcell, lastcell,false,true)
    firstcell:[0,0], lastcell[rowcount-1,colcount-1]
    Result: only the first row selected when i use both methods.
    Note: i set up the selection model as following:
    this.dataSheet.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                    this.dataSheet.setCellSelectionEnabled(true);
                    this.dataSheet.setRowSelectionAllowed(true);
                    this.dataSheet.setColumnSelectionAllowed(true);Thanks !

    What selection properity should be changed in order to enable selectAll() method work properly? Is there Any constraints? Here is the TableModel I am using. And i set up selection mode use the following code:
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setCellSelectionEnabled(true);
    table.setRowSelectionAllowed(true);
    table.setColumnSelectionAllowed(true);
    import java.util.Vector;
    import javax.swing.table.*;
    import javax.swing.JTable;
    public class DataSheetModel extends AbstractTableModel{
              private Vector data = new Vector();//Store data
              private Vector columnNames = new Vector();//Store head
              public DataSheetModel(){}
              public DataSheetModel(Vector headVector, Vector dataVector){
                   if(headVector != null) this.columnNames = headVector;
                   if(dataVector != null) this.data = dataVector;
              public int getColumnCount(){
                   return columnNames.size()+1;
              public int getRowCount(){
                   return data.size()+1;
              public String getColumnName(int col){
                   if(col==0) return "";
                   else return (String)columnNames.get(col-1);
              public Object getValueAt(int row, int col){
                   if(col==0) {
                        if(row != data.size()) return String.valueOf(row);
                        else return "*";
                   else{
                        if(row != data.size()){
                             Vector rowVector = (Vector)data.elementAt(row);
                             return rowVector.elementAt(col-1);
                        }else return null;
              public void setValueAt(Object value, int row, int col){
                   if(row != this.data.size()){
                        Vector rowVector = (Vector)data.elementAt(row);
                        rowVector.set(col-1,value);
                        this.data.set(row,rowVector);
                        this.fireTableDataChanged();
                   }else{
                        Vector rowVector = new Vector();
                        for(int i=0; i<this.getColumnCount()-1; i++) rowVector.add(null);
                        rowVector.set(col-1,value);
                        this.data.add(rowVector);
                        this.fireTableDataChanged();
              public Class getColumnClass(int c){
                   return getValueAt(0,c).getClass();
              public boolean isCellEditable(int row, int col){
                   if(col == 0) return false;
                   else return true;
              public void setDataVector(Vector head, Vector data){
                   if(head != null) this.columnNames = head;
                   if(data != null) this.data = data;
    }

  • Merge cells in JTable.......

    Plz some help me out ......i want to merge two consecutive cells of a row in one cell in JTable......... how to do that.....give some code if possible....

    Well, as a new member you should learn to search the forum first before posting questions. Using keywords like "jtable merge cell" will find other postings on this topic. Some with solutions some without, so you will need to read a few and decide on the approach you want to take.

  • Text position in a cell in JTable?

    hello experts!!
    how can i center(horizontal) position/left/right justified a text in a cell in JTable?
    plz help.. tnx in advance!

    kagaw3000 wrote:
    ok i got it!
    But i am really confuse in JTable tutorial. it uses JLable as a CellRenderer and JButton as a CellEditor
    then it returns a Color.
    for clarification, when i am editing a cell, CellEditor will takes place, right? and when customizing the display of a cell, CellRendere will takes place, right?
    There is a very good explanation at the beginning of the Concepts: Editors and Renderers section in the tutorial.
    can you show me code that get and return a String not a Color.class?The default editor GenericEditor of JTable uses a JTextField which returns a String:
    static class GenericEditor extends DefaultCellEditor {
        Class[] argTypes = new Class[]{String.class};
        java.lang.reflect.Constructor constructor;
        Object value;
        public GenericEditor() {
            super(new JTextField());
            getComponent().setName("Table.editor");
        public boolean stopCellEditing() {
            String s = (String)super.getCellEditorValue();
            // Here we are dealing with the case where a user
            // has deleted the string value in a cell, possibly
            // after a failed validation. Return null, so that
            // they have the option to replace the value with
            // null or use escape to restore the original.
            // For Strings, return "" for backward compatibility.
            if ("".equals(s)) {
                if (constructor.getDeclaringClass() == String.class) {
                    value = s;
                super.stopCellEditing();
            try {
                value = constructor.newInstance(new Object[]{s});
            catch (Exception e) {
                ((JComponent)getComponent()).setBorder(new LineBorder(Color.red));
                return false;
            return super.stopCellEditing();
        public Component getTableCellEditorComponent(JTable table, Object value,
                boolean isSelected,
                int row, int column) {
            this.value = null;
            ((JComponent)getComponent()).setBorder(new LineBorder(Color.black));
            try {
                Class type = table.getColumnClass(column);
                // Since our obligation is to produce a value which is
                // assignable for the required type it is OK to use the
                // String constructor for columns which are declared
                // to contain Objects. A String is an Object.
                if (type == Object.class) {
                    type = String.class;
                constructor = type.getConstructor(argTypes);
            catch (Exception e) {
                return null;
            return super.getTableCellEditorComponent(table, value, isSelected, row, column);
        public Object getCellEditorValue() {
            return value;
    }

Maybe you are looking for

  • Just updated to Ver 34 and my favorite addon"flashblock" is incompatible to ver 34.

    Does anyone know a substitute that will block videos from opening automatically on new sites etc? When I open multiple sites videos start playing from all of them at once. Flashblock always let me click on the individual videos to start them. Thank y

  • Multiple output types in MIGO_GI

    Hi all, In my current setting, a message type would be created and printed immediately once the material doc. of goods issue (MIGO_GI) is posted. (Movement type = 261) Now, it is required to offer some flexibility to users when printing the mat. doc.

  • How to apply the filter condition based on other column

    HI, i have one requirement. i am giving the example below.my 2 columns data like below Column1 Column2 A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 i want to give Column1 as a dashboard prompt and users will enter A,B,...(what are all in the column1). what i want

  • Oracle sga advisor results

    hello all, When querying this view in regards to the v$sga_shared_pool advisory , i get results but not sure how to interpret the ESTD_LC_TIME_SAVED column ? It's a time in seconds benchmark to what exactly ? EST_SIZE FACTOR ESTD_LC_SIZE ESTD_LC_TIME

  • MobileMe vs iCloud for file sharing

    I was using Mobile me for  a transfer for files to my clients does I cloud allow me to do that?