Results 1 to 6 of 6
  1. #1
    phungho2000 is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default How to add JTextArea in JTable - Swing

    I'd like to know how to add TextArea to the table in the code below(any column). Thanks in advance.

    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    public class TableWithTextArea extends JFrame
    {
    /**
    *
    */
    private static final long serialVersionUID = 1L;

    JPanel pan = new JPanel();
    DefaultTableModel defaultModel = new DefaultTableModel();
    JTable table = new JTable(defaultModel);
    JScrollPane scroll = new JScrollPane();
    JTextArea ta = new JTextArea(20, 20);
    JTextField tfField = new JTextField(10);
    public TableWithTextArea()
    {
    setTableColumns();
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COL UMNS);
    // table.setCellEditor(new DefaultCellEditor(ta));
    scroll.setViewportView(table);
    this.getContentPane().add(scroll);
    }
    private void setTableColumns()
    {
    // TODO Auto-generated method stub
    defaultModel.addColumn("Column 1");
    defaultModel.addColumn("Column 2");
    defaultModel.addColumn("Column 3");
    defaultModel.addColumn("Column 4");
    defaultModel.addColumn("Column 5");
    defaultModel.addColumn("Column 6");
    }
    public static void main(String[] s)
    {
    TableWithTextArea twa = new TableWithTextArea();
    twa.setLocation(300, 200);
    twa.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
    twa.pack();
    twa.setVisible(true);
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There is no DefaultCellEditor constructor that takes a JTextArea as a parameter. You may need to create your own cell editor overriding the AbstractCellEditor class and using it to incorporate a JTextArea. I'm no pro at this so I don't know if it actually will work, but I don't see why not.

  3. #3
    phungho2000 is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default

    Can anyone please give me an example in the code. I am stuck on this for about two days. I've searched everywhere but did not find any code sample for this. I've also try many difference methods but It seemed this is more than my knowledge. Please help.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    If you google on the terms: JTextArea and AbstractCellEditor, you'll find some pretty helpful hits. Also try searching this forum and the forums.sun.com forums on the same terms for more useful hits.

    Best of luck.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

  6. #6
    phungho2000 is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Inside a Timer thread loop,how to refresh a JTable in swing
    By neha_negi in forum Threads and Synchronization
    Replies: 3
    Last Post: 09-04-2009, 01:45 AM
  2. Java Swing JTable Simple Doubt
    By hemanthjava in forum AWT / Swing
    Replies: 1
    Last Post: 11-26-2008, 01:46 PM
  3. Swing problem: JTable/TableModel
    By Levish2002 in forum AWT / Swing
    Replies: 2
    Last Post: 08-24-2008, 08:53 PM
  4. Replies: 2
    Last Post: 05-15-2008, 10:15 AM
  5. JTextArea
    By saytri in forum New To Java
    Replies: 0
    Last Post: 01-13-2008, 01:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •