How to add JTextArea in JTable

Hi..
I want to add JTextArea in my table in one of the column of JTable. I have already written a code which implements TablecellEditor and TableCellRenderer. I have already succeeded to set textarea in one cell for multiple line but when i go to another cell my previous value disappears. Can anybody tell me the solution.

I think the reason that this is happening, is that you have to override the setValue method in TableModel, inorder for the value to be displayed correctly.
Another thing.
I too am trying to implement a textarea as one of the cells in a col.
But the problem is that when I create my celleditor extends TextArea and implements TableCellEditor, and compile it says that all eventLsiteners are already implemented .
And if I just extend the AbstractCellEditor, and return it in the method getCellEditor, it says incompatible types.
Can you tell me how to implement a CustomCellEditor
Thanks,

Similar Messages

  • How to add data into JTable

    How can I add data into JTable, for instance ("Mike", "Gooler", 21).

    How can I add data into JTable, for instance ("Mike",
    "Gooler", 21).You will have very good results if you segregate out the table model as a seperate user class and provide a method to add a row there. In fact, if you use the table to reflect a database table you can add the row inplace using the existing cursor. I believe it's TableExample2 in the jdk\demo\jfc\TableExamples that has a very good example of this.
    Walt

  • How to add events in JTable fields

    Hello friends i m working with file transfer client server project in my college.In my client part i have used JTable with AbstractTableModel.
    In my JTable it list the current directory files and directories under current directory .
    now how can i add events to the the directories that it shows on JTable so that when i click on directory it displays files under that selected directory.
    can anyone help me in that.
    I will send you my code for that project if anyone can help me.
    please help me to do that

    You can handle row selections with selection listener but if you want to handle double clicks you can use something similar to this:
    table.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    int column = table.columnAtPoint(e.getPoint());
    int row = table.rowAtPoint(e.getPoint());
    Object cellValue = table.getValueAt(row, column); 
    // Insert files below clicked row
    });Please, be more patient in the future -you would probably get an answer if you just posted to any of these two forums.

  • How to add actionlistener to JTable?

    I have created a JTable. and I would like to while I double-click any row of JTable, I go to next frame. How can I add actionlistener to each row?

    Here's an example:
    TableF modeltable = new TableF();
    JTable FuncsTable = new JTable(modeltable);
    FuncsTable.addMouseListener(mlTable);
    MouseListener mlTable = new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    if ( e.getClickCount() == 2 ) {
    System.out.println( FuncsTable.getSelectedRow());
    your code

  • How to add  ComboBox in Jtable Header

    Hello everyone,
    I want to add a Combox box in JTable Header .Basically it works as central access to whole table e.g. by selecting delete row in combo box then it should delete the current selected row.If somebody has any idea please share it.
    Thanks in advance.

    The individual headers are not Swing components and therefore do not respond to mouse events in the same way as Swing components. Why don't you just have a popup menu that is positioned over the currently selected row? If you want to apply an action to all selected rows then have a set of buttons placed above the table header.

  • How to add Chekbox in Jtable?

    I am working on Swing application and my requirement is add new column that dispay the checkboxes, so user have the access to check/uncheck row for further process.
    In application 3 tabbedpanes are there & in the 3rd tabbedpane table data is displaying.
    //Code snippet
    public class AIProductPropertiesUI
    private productsTablemodel productmodel = null;
    private String [] pNames = {"select","type","name","revision","marketing","relationship"};
    public JPanel getMiscPanel()
    productmodel= new productsTablemodel();
    table = new JTable(productmodel);
    protected class productsTablemodel extends AbstractTableModel
    Vector productDetails ;
    productsTablemodel()
    productDetails = model.getProductDetails();
    headerNames = model.getLabelNameMapping();
    public Object getValueAt(int rowIndex, int columnIndex)
    if (productDetails.size()>0)
    Hashtable ht = (Hashtable) productDetails.get(rowIndex);
    //ht contains the list of values for all the column as in pNames[].
    // dynamic value for Select column is ""(blank string)
    String str = "" ;
    if(ht.containsKey(pNames[columnIndex]))
    str = (String) ht.get(pNames[columnIndex]);
    return str;
    }else{
    return null;
    I tried following ways-
    1)if(column==0)
    return new JCheckBox("str",true);
    here output is dispaying complete details of Checkbox
    /* output for checkbox cell is --- javax.swing.JCheckBox[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,
    border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@b1b4c3,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,
    disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=false,paintFocus=true,
    pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=str]*/
    2)overiding public Class getColumnClass(int column)
    if(column==0)
    return Class.forName("java.lang.Boolean");
    till this point its working fine... but in above code method public Object getValueAt(int rowIndex, int columnIndex)
    I am checking if(Column==0)
    return Class.forName("java.lang.Boolean");
    here it is throwing ClassCastException.. java.lang.Class cannot be cast to java.lang.Boolean
    Please provide me solution aas soon as possible...coz from past 2 days i m stucking on this and due to this not able to move ahead on my application development.
    Thanks in Advance
    Sharad

    more time researching instead of cross-posting would be better for you
    [http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=018027]

  • How to add KeyListener on JTable

    Hello everybody,
    I have a Jtable and i want to use the up and down key on the keyboard. I don't find the method how allow me to do that. I try "addKeyListener" but no result.
    Please help me !!!!
    Thanks .
    PS : excuse for my bad english.

    i try to be clear :o)))
    I have a text on a JtextPane and i have a table (include in a JSrcollPane)
    when i clicked in the text, il select the good entry in the table, when a do the same (by clicking addmouselistener) on the Jtable i hightlight un part of text. OK !!! for this its good !!!
    The second thing i must doing :
    when i use the up and down key on the Jtextpane its good i have the comportment describe before. But when i use the up and key doxn in my table its doesnt work !!!
    the focus is also in my jtextpane, this event is not catch by my Jtable but by JtextPane

  • HOW TO ADD COLORS TO JTABLE ROWS??

    I want to change the colors of alternate rows in my JTable. I am doing so using CellRenderer, but then I am not able to view the selected rows.
    tell me how can I change the row color as well as a selected row should be identifiable from others, as ordinary JTable.
    thanks

    Hi,
    try this:
    define your own DefaultTableCellRenderer like this:
    class MyRenderer 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 (isSelected) setBackground( Color.anyColor );               
    return this;
    Hope it helps!
    Regards, Paul

  • How to add unicode in jtables?

    Well basically the name of the topic is the question. If you could show it directly in the code below that would be really great. Thanks.
    import javax.swing.*;
    public class TestUnicode extends JFrame {
         JTable table;
         String[] names = {"Name"};
         String[][] data = {{"GBP: \00A3"}, {"EUR: \20AC"}};
         public TestUnicode() {
              setTable();
              getContentPane().add(new JScrollPane(table));
              setSize(300, 300);
              setLocationRelativeTo(null);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
         private void setTable() {
              table = new JTable(data, names);
         public static void main(String args[]) {
              new TestUnicode();
    }

    Add a lowercase "u" (for unicode) after your slashes: \u20AC.

  • How to add image in jtable header using 'Default table model'

    Hi,
    I created a table using "DefaultTableModel".
    im able to add images in table cells but not in 'table header'.
    i added inages in table by overriding "getColumnClass" of the DefaultTableModel.
    But what to do for headers?
    please help.
    Thanks in advance.

    The 'Java 5 tutorial' is really an outstanding oneI should note the the current tutorial on the Sun website has bee updated for Java 6. It contains updates to reflect the changes made in JDK6. Once of the changes is that sorting of tables is now supported directly which is why I needed to give you the link to the old tutorial.
    http://java.sun.com/docs/books/tutorial/uiswing/TOC.html

  • SAMPLE CODE  + HOW ADD JCOMBOBOX IN JTABLE

    HI,
    ALL OF U
    PLZ SUGGEST ME HOW TO ADD COMBOBOX IN JTABLE.
    AND ALSO TELL HOW WE CAN ADD ITEMS IN COMBOBOX AT RUN TIME.
    PLZ SUGGEST ME.
    THANX IN ADVANCE.
    BYE

    Hi if you google you find a lot
    http://www.google.be/search?q=JTable+combobox&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:nl:official&client=firefox-a
    and
    http://www.google.be/search?q=JTable+combobox+example&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:nl:official&client=firefox-a
    Satanduvel

  • Add JTree in JTable

    How to add JTree in JTable?
    Please tell me?

    you need to use a TableCellRenderer, that implements your JTree, for cell renderers see http://java.sun.com/docs/books/tutorial/uiswing/components/table.html and http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer
    thomas

  • How to add name from text file to jtable?

    hello all,
    how to add name (string) from the notepad file(.txt) into jTable rows.
    I am not able to add it.
    try {
                 FileInputStream fis = new FileInputStream("Devices/Devices_Lst.txt");
                 BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                 String line = null;
                 Vector data = new Vector();
                 line = br.readLine();
                 while ( (line = br.readLine()) != null)
                    int rowCount1 = nmsTable.getRowCount();
                    for(int i=0;i<rowCount1;i++)      
                        myTableInit();  // it initialize the table
                       /* nmsTable.setValueAt(i+1,i,0);
                        Table.setValueAt(line,i,1);
                        Table.setValueAt(" ",i,2);
                        Table.setValueAt(" ",i,3);
                        Table.setValueAt(" ",i,4);
                        Table.setValueAt(" ",i,5); */
                        int rowNo = nmsTable.getRowCount();
                        row.addElement((rowNo+1));
                           //row.addElement(ipText.getText()+"-"+nameText.getText());
                           row.addElement(line);   
                           row.addElement((String)" ");
                           row.addElement((String) "");
                           row.addElement((String) "");
                           row.addElement((String) "");      
                            row.addElement((String) "");      
                            rows.add(row);                                     //rows is the Vector for table row.
                            Table.addNotify(); 
                  br.close();
                 if possible give me some examples.
    thank you.

    For every row you need to create a new Vector and add the data to that Vector. Then the Vector is added to the TableModel.
    If you add 6 items to the single Vector, then you will get 6 columns. So you need to create 6 Vectors and add a single item to each Vector and therefore you will end up with 6 rows with 1 column of data.

  • How to add row in a JTable at runtime.

    Hi,
    How to add a row in JTable at runtime? I am using my own TableModel object extended from AbstractTableModel.
    Thanks in advance.

    try this link... i have answered this forum.
    http://forum.java.sun.com/thread.jspa?threadID=5242581

  • How to edit databases from JTable?

    Hello everyone, I would like to ask your help on how we can edit JTable cells that would be reflected into the database, or how do we change the database via a JTable.
    I have the installer of an application which I made with Java SE called FuelStation.exe
    My class files are ready for sharing along with its source files.
    I have placed it in this location in my website:
    http://www.apachevista.com/alphaprojects/runfiles/
    It is complete with full details about databases, proposed mysql embed, and so on. Please see the file and notify me at [email protected]
    Here is my sample code:
    // DisplayQueryResults.java
    // Display the contents of the Authors table in the
    // Books database.
    import java.awt.BorderLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.sql.SQLException;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.JTable;
    import javax.swing.JOptionPane;
    import javax.swing.JButton;
    import javax.swing.Box;
    import javax.swing.JInternalFrame;
    import java.util.*; // for the Bundle
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    import javax.swing.event.InternalFrameAdapter;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.event.*; // step 1
    import javax.swing.table.TableModel; // step 1
    public class DisplayQueryResults extends JInternalFrame implements TableModelListener { // step 2
    // JDBC driver, database URL, username and password
    ResourceBundle bundle = ResourceBundle.getBundle("Accounting");
    final String JDBC_DRIVER = bundle.getString("Driver");
    final String DATABASE_URL = bundle.getString("URL");
    final String USERNAME = bundle.getString("User");
    final String PASSWORD = bundle.getString("Password");
    // default query retrieves all data from authors table
    //static final String DEFAULT_QUERY = "SELECT authors.lastName, authors.firstName, titles.title, titles.editionNumber FROM titles INNER JOIN (authorISBN INNER JOIN authors ON authorISBN.authorID=authors.authorID) ON titles.isbn=authorISBN.isbn";
    final String DEFAULT_QUERY = bundle.getString("Query");
    private ResultSetTableModel tableModel;
    private JTextArea queryArea;
    static final int xOffset = 0, yOffset = 200;
    private boolean ALLOW_COLUMN_SELECTION = false;
    private boolean ALLOW_ROW_SELECTION = true;
    // create ResultSetTableModel and GUI
    public DisplayQueryResults() {  
    super("Sales of the Day",
    true, //resizable
    true, //closable
    true, //maximizable
    false);//iconifiable
    //...Create the GUI and put it in the window...
    //Set the window's location.
    setLocation(xOffset, yOffset);
    // create ResultSetTableModel and display database table
    try {
    // create TableModel for results of query SELECT * FROM authors
    tableModel = new ResultSetTableModel(JDBC_DRIVER, DATABASE_URL,
    USERNAME, PASSWORD, DEFAULT_QUERY);
    // set up JTextArea in which user types queries
    queryArea = new JTextArea(DEFAULT_QUERY, 1, 100);
    queryArea.setWrapStyleWord(true);
    queryArea.setLineWrap(true);
    JScrollPane scrollPane = new JScrollPane(queryArea,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // set up JButton for submitting queries
    JButton submitButton = new JButton("Submit Query");
    // create Box to manage placement of queryArea and
    // submitButton in GUI
    Box box = Box.createHorizontalBox();
    box.add(scrollPane);
    box.add(submitButton);
    // create JTable delegate for tableModel
    JTable resultTable = new JTable(tableModel);
    resultTable.setFillsViewportHeight(true); // Makes the empty space heights white
    resultTable.setRowSelectionAllowed(true);
    resultTable.getModel().addTableModelListener(this); // step 3
    // place GUI components on content pane
    add(box, BorderLayout.NORTH);
    add(new JScrollPane(resultTable), BorderLayout.CENTER);
    // create event listener for submitButton
    submitButton.addActionListener(
    new ActionListener()
    // pass query to table model
    public void actionPerformed(ActionEvent event)
    // perform a new query
    try
    tableModel.setQuery(queryArea.getText());
    } // end try
    catch ( SQLException sqlException)
    JOptionPane.showMessageDialog(null,
    sqlException.getMessage(), "Database error",
    JOptionPane.ERROR_MESSAGE);
    // try to recover from invalid user query
    // by executing default query
    try {
    tableModel.setQuery(DEFAULT_QUERY);
    queryArea.setText(DEFAULT_QUERY);
    } // end try
    catch (SQLException sqlException2) {
    JOptionPane.showMessageDialog(null,
    sqlException2.getMessage(), "Database error",
    JOptionPane.ERROR_MESSAGE);
    // ensure database connection is closed
    tableModel.disconnectFromDatabase();
    System.exit(1); // terminate application
    } // end inner catch
    } // end outer catch
    } // end actionPerformed
    } // end ActionListener inner class
    ); // end call to addActionListener
    //...Then set the window size or call pack...
         setSize(750,300);
    setVisible(true); // display window
    } // end try
    catch (ClassNotFoundException classNotFound) {
    JOptionPane.showMessageDialog(null,
    "MySQL driver not found", "Driver not found",
    JOptionPane.ERROR_MESSAGE);
    System.exit(1); // terminate application
    } // end catch
    catch (SQLException sqlException) {
    JOptionPane.showMessageDialog(null, sqlException.getMessage(),
    "Database error", JOptionPane.ERROR_MESSAGE);
    // ensure database connection is closed
    tableModel.disconnectFromDatabase();
    System.exit(1); // terminate application
    } // end catch
    // dispose of window when user quits application (this overrides
    // the default of HIDE_ON_CLOSE)
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    // ensure database connection is closed when user quits application
    addInternalFrameListener(
    new InternalFrameAdapter() {
    // disconnect from database and exit when window has closed
    public void windowClosed(WindowEvent event) {
    tableModel.disconnectFromDatabase();
    System.exit(0);
    } // end method windowClosed
    } // end WindowAdapter inner class
    ); // end call to addWindowListener
    } // end DisplayQueryResults constructor
    public void tableChanged(TableModelEvent e) { // step 4
    int row = e.getFirstRow();
    int column = e.getColumn();
    TableModel model = (TableModel)e.getSource();
    String columnName = model.getColumnName(column);
    Object tableModel = model.getValueAt(row, column);
    // Do something with the data...
    System.out.println(tableModel);
    System.out.println("data");
    // execute application
    public static void main(String args[]) {
    new DisplayQueryResults();
    } // end main
    } // end class DisplayQueryResults
    My question is in lines 177-187:
    public void tableChanged(TableModelEvent e) { // step 4
    int row = e.getFirstRow();
    int column = e.getColumn();
    TableModel model = (TableModel)e.getSource();
    String columnName = model.getColumnName(column);
    Object tableModel = model.getValueAt(row, column);
    // Do something with the data...
    System.out.println(tableModel);
    System.out.println("data");
    Why is my listener not working or why is it not implemented when I click the cells in the JTable and why is it not reflected into the JTable or into the console?
    If this is Flash, Things can be done easily, but this is Java, and I dont know much about this language. I admit that I am new to this -intirely new.
    PS:
    When you have solved the problem, please notify me with the code that's changed
    and please share it to others if you like so.
    Best Wishes: Oliver Bob Lagumen
    Email: [email protected]
    website: www.apachevista.com
    Oliver Bob Lagumen
    Edited by: Oliverbob on Jan 24, 2008 9:03 PM

    Why is my listener not working or why is it not implemented when I click the cells in the JTable and why is it not reflected into the JTable or into the console?What does happen when you click on the cells?
    Does the ResultSetTableModel report the cells as editable? If not you will never get to edit their contents, and so the table's model won't change, and so the table model listener will never get invoked.
    When you post code here use the code tags. Basically you put {code} at the start of your code and again at the end. That way the code will be readable.
    Try to post minimal examples with which others can reproduce your problem. In this case "minimal" would involve removing or drastically simplifying a lot of the GUI stuff which is just noise. But "reproduce" would involve including the ResultSetTableModel.
    When you have solved the problem, please notify me with the code that's changedAvoid this.
    What you say here is quite possibly not what you mean. But, in any event, while there might be plenty of interest in helping with specific problems there will likely be none in writing your code. Your problem remains yours. But your solution and your code - prompted by whatever help you might recieve - will also be yours.

Maybe you are looking for

  • Access Denied error with basic XML file operations

    Hi, I'm trying to set up a basic read, write and delete code for XML files which I can build upon in the future. The three methods are bound to three buttons on the page and all three calls are awaited. Here's my code: Write: XElement uservarnodes =

  • My phone won't download my music

    My phone won't download my music purchases and I can't sync my music from my computer

  • Can I connect Mac mini to Windows laptop?

    I would like to connect Mac Mini to HP windows 7 Laptop as to use the laptop as keyboard and monitor instead of connecting to TV and using separate keyboard. Is this straight forward to do? does it need some workaround? or is it impossible?

  • ICloud Photostream Mac vs PC

    So, in setting up iCloud Photostream synchronization on my Mac and PC, Mac requires iPhoto to sync.  My ultimate goal is to auto-download the pictures that I take on my iPhone without intervention.  On the PC, my photos automatically download to a fo

  • 7.2 ICM Script - Need to Grep for data within Formula Editor

    We  have a massive SET_SKILL script.  I'm the FNG and have been tasked with grepping every IF node in this script and using the formula editor to determine the 4 digit Route Code and where that Route Code is being routed. The current engineering team