Results 1 to 6 of 6
- 12-17-2008, 03:32 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 3
- Rep Power
- 0
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);
}
}
-
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.
- 12-17-2008, 03:45 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 3
- Rep Power
- 0
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.
-
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.
- 12-17-2008, 06:14 AM #5
- 12-17-2008, 09:18 PM #6
Member
- Join Date
- Dec 2008
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Inside a Timer thread loop,how to refresh a JTable in swing
By neha_negi in forum Threads and SynchronizationReplies: 3Last Post: 09-04-2009, 01:45 AM -
Java Swing JTable Simple Doubt
By hemanthjava in forum AWT / SwingReplies: 1Last Post: 11-26-2008, 01:46 PM -
Swing problem: JTable/TableModel
By Levish2002 in forum AWT / SwingReplies: 2Last Post: 08-24-2008, 08:53 PM -
Jtable duplicates through Hashtable (JTable condition problem) my assignment plz help
By salmanpirzada1 in forum Advanced JavaReplies: 2Last Post: 05-15-2008, 10:15 AM -
JTextArea
By saytri in forum New To JavaReplies: 0Last Post: 01-13-2008, 01:07 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks