JList to JTable questions

Hi, from looking at discussion groups and forums it appears that JList does not support the editability function; therefore, people suggest using a one column table instead.
In changing the code around, I have a few questions
Originally, I have the following for JList so that I can detect whenever
an item has been deleted or added to the list
activeModelList.getModel()
.addListDataListener(new ListDataListener() {
Now, the activeModelList is actually a JTable with a model that is a DefaultTableModel instead of DefaultListModel. How can I still be able to detect changes? what type of Listener can I use?
Then, originally I had indicated default selections in the JList using the following activeModelList.setSelectedIndex(1); The only thing that I could think of to do the same for the table was activeModelList.setRowSelectionInterval(1,0); Is this good programming practice? Is this correct?
Thank you very much for your inputs and advice.

I think i figured out the .addListDataListener(new ListDataListener() equivalent... anyone know how to convert activeModelList.addListSelectionListener(new ListSelectionListener() {
to one that would work the same in JTable
someJTableFormerActiveModelList.add?

Similar Messages

  • JList inside JTable

    Hi,
    I have a custom JList Renderer/Editor inside a JTable. Both the renderer and editor seem to be working fine, but if the List contains more data than will fit in the table cell, you can't see the rest of the data. I have a separate class for the renderer and the editor (both of which extend JList) and I have tried using the setAutoscrolls method and creating a JScrollPane in the constructor, neither of which seems to work. How can I put a scrollable JList as a cell in a JTable?

    Hi jhooie,
    Will you please send me the working codes for creating the JList inside JTable. I am in urgent need of the help.
    My email id is [email protected]
    Thank you,
    satheesh kumar

  • Rephrasing of JTable question

    Ok, I'm going to rephrase a question I put up pretty poorly about JTables. This is what how I see it. I wanted to create a JTable with a button as the last column, a delete button that will allow you to delete that row. Sounds simple enough - I figured out how to add that last column, and how to create my own TableCellRenderers such that it rendered the last column as a button representation.
    Now my design question relates to the fact that the actual data, doesn't reside on the table...the actual data sits in another data object (a data array), and the table merely renders that information in a specific way. So when I hit the delete button, I really don't have a handle to the data, I need to somehow have an actionListener listening to that button which then sends a message to something else that is holding that data, and informs it to delete that item. The only way I see that is to pass a handle in the constructor of the TableCellRenderer of the actionListener which has a handle to the actual data. Is that how things are done? All this just so that an action performed on the Jtable looks like it's affecting the data itself?
    Correct me if I'm wrong, but it seems like the implementation of this JTable has it such that even though when I addRows to the JTable I am passing an actual object to the JTable. The JTable will just convert the object into textual information, and the handle of that actual object will be lost. In some ways it seems like it would have been better if that JTable kept a handle to the object passed into it from addRow(), so that if I ever said delete this row, I don't have to jump through hoops to find which data object is represented by that particular row and then have something else delete. Instead it would say "Ok, delete this row, which is really this object." Or maybe there is a reason that isn't done.
    Message was edited by:
    deadseasquirrels

    I read the post where you used the removeColumn method of the columnModel to remove the columns that you do not want to display. The way I understand it is that it is implementation of the MVC model, where the data is still there, but the Viewer aspect of the table just isn't displaying the data - and as you showed in your example, that gives more flexibility when you want to share a certain data table, but have it displayed differently.
    But it seems to me that the lines of code:
    columnModel1.removeColumn( columnModel1.getColumn( 4 ) );should really be sitting in either the tableModel class, or the renderer class. At this point that line of code, which defines which columns table1 or table2 should display just sits in the main object class. It seems to me that to be more robust in your tableModel definition, somewhere it should say "any table that uses this table model will have columns x, y, z removed from the columnModel." Instead by having that line of code just sitting outside of either a renderer class or a tableModel class that line could be anywhere, and it doesn't seem too robust. I guess I'm mentioning it, because I would like to put it in either the renderer class or my tableModel class (shown below), but I don't see how I can do that. If I can't do that perhaps you can shed some light as to why my understanding is flawed, and why they designed it in such a way that you can't - right now it seems like the tableModel class would be a great place to put a line of code like that.
    private DefaultTableModel filledTableModel = new DefaultTableModel(data, transactionCols){
    // Only allow button column to be editable, if there is an actual
    // button in that row          
        public boolean isCellEditable(int row, int col){
            return (col == CANCEL_COL && getValueAt(row, col) != "") ? true : false;
        // Overriden getColumnClass method that will return the object
        // class type of the first instance of the data type otherwise
        // returns the Object.class
        public Class getColumnClass(int column){
            for (int row = 0; row < getRowCount(); row++){
                Object o = getValueAt(row, column);
                if (o != null){ return o.getClass();
            return Object.class;
    };

  • Combobox in JTable question

    Hello,
    I have to make a button in a JTable that is activated with a right button and then like in a combobox appears a menue and every item in this menue should be activated with the left button and perform some action. Like in windows right click and then select smth.
    My question is should I do it with Combobox and if yes how to activate it with the right button because it always listens to left button. It is implemented with action listener and I tried mouse listener but it wouldn"t listen to that. I will be glad to any solutions.
    Thanx,
    Miroslav

    Hi,
    And thank you for the answer. i think I will use jpop menu as u sujested(Thank you for that). Now I should only see how to make the render and the editor to put it in a cell in a JTable.
    It should be activated with the right button, beacause my task is such and because I also think that it is better this way. II mean it is more natural than with the left button.
    Miroslav

  • 2 JTable question

    1) In a default model JTable how can I deselect all selected rows or cancel any selection, since a table.deselectAll() method does not exist.
    2) How can I move selection. For example when I press a down arrow button the selection should move down with one row.
    Any help is highly appreciated.

    Next time make use of the correct forum for the specifyed question, in this cause the swing forum.
    Anyhow.
    1) In a default model JTable how can I deselect all selected rows or cancel any selection, since a table.deselectAll() method does not exist.Use JTables clearSelection(); ??
    2) How can I move selection. For example when I press a down arrow button the selection should move down with one row.Add an keylistener to the arrow button? And when its pushed, get the currently selected row, and set the new selected row to be current row + 1?
    getSelectedRow() And setRowSelectionInterval() perhaps?
    Use the Java api: http://java.sun.com/javase/6/docs/api/

  • JTable question/problem

    I am extracting data from 3 different database tables and I want to display the contents in seperate JTables, I am developing a table model class as a subclass of AbstractTableModel to be passed to the constructor of my JTable but because I will be creating 3 different JTable objects, does this mean that I must create 3 different table model classes as well? or is there an easier way of creating more than one table model in a class and selecting when to use them.

    I need to create a seperate model because the tables in the database do not have any shared columns Then I don't understand your original question. It appears you've answered your own question. Yes, you need a separate TableModel for each table.
    and some of the tables have data in a boolean and date format which I'm not sure are displayed properly with the default model. The TableModel is used to store data. You can control how the data is displayed at the JTable level. Check out this [url http://forum.java.sun.com/thread.jsp?forum=57&thread=419688]thread.

  • JTable question regarding Index/ID's from a VB guy

    Greets!
    So i am coming from VB6 where i use an ActiveX object table to display data from a SQL database table. When populating the table i include the 'ID' field from the database table as a hidden column. So when a user selects a row, i pull the hidden column's ID# and use that to do whatever (bring up another edit form, etc)
    So here i am in Java now, i've been playing with jTable for a while now and seem to be getting the hang of the basics, but when i replicated the above scenario, hiding the ID column had weird results (cursor would dissappear when i scroll over with the arrow keys). I also saw another post where another person said that along with populating the jTable i should also have an array that stores the ID that matches the RowIndex from the jTable itself.
    This is the table model that i am using:
    public class jTableModel extends AbstractTableModel {
        private double xTotal;
        private int colnum;
        private int rownum;
        private String[] colNames;
        private  ArrayList<Object[]> ResultSets;
        private Icon zIcon;
        /** Creates a new instance of FoodTableModel */
        public jTableModel(ResultSet rs,frmMain frm) {
          ResultSets=new ArrayList<Object[]>(); 
          Icon icon1 = new ImageIcon(getClass().getResource("/main/images/bullet_ball_glass_blue.png"));
          Icon icon2 = new ImageIcon(getClass().getResource("/main/images/bullet_ball_glass_red.png"));
          Icon icon3 = new ImageIcon(getClass().getResource("/main/images/bullet_ball_glass_green.png"));
          try{
            while(rs.next()){
                switch (rs.getInt("Type")) {
                    case 1: zIcon = icon1; break;
                    case 2: zIcon = icon2; break;
                    case 3: zIcon = icon3; break;
                Object[] row={zIcon,rs.getString("Name"),rs.getString("Description"),rs.getString("ID")};
                ResultSets.add(row);
            String[] zNames={
                "","Name","Description","ID"
            colNames = zNames;
            colnum=4;
          catch(Exception e){
              System.out.println("(jTableModel: There was an error: " + e);
        public Object getValueAt(int rowindex, int columnindex) {
           Object[] row=ResultSets.get(rowindex);
           return row[columnindex];
        public int getRowCount() {
            return ResultSets.size();
        public int getColumnCount() {
            return colnum;
        @Override
        public String getColumnName(int param) {
           return colNames[param];
        public double getTotal() {
            return xTotal;
        @Override
        public Class getColumnClass(int column) {
         return getValueAt(0, column).getClass();
        }Can anyone give me any tips in this area or point me in the right direction?
    Any help would be appreciated.

    Dear Poster,
    As no response has been provided to the thread in some time I must assume the issue is resolved, if the question is still valid please create a new thread rephrasing the query and providing as much data as possible to promote response from the community.
    Best Regards,
    SDN SRM Moderation Team

  • A few JTable questions

    Hi,
    I'm doing a bit of experimentation with JTables and have a few questions. What I am trying to do
    is create a JTable in a horizontal format, so that the headings appear as columns on the left hand side, and only the non-headers are editable.
    Is it possible to create a JTable with no column headers? I've looked up some of the examples on the web about having row headings, but the code seems very convoluted and difficult for me to understand, most involving JScrollPanels.
    If this is possible,
    What will happen when the values edited? eg. if I edit a value on the first row, will setValueAt (extended from AbstractTableModel's method) assume row=1 rather than 0 because it is expecting a column header?
    Also, the data for the table is held in another class, for instance:
         double timeStep[] = {0,40,80,120,160,200,240,280,320};
         double trim[] = { 26.2, 23.0, 23.0, 23.0, 23.0, 29.1, 45.0, 75.4, 90.0 };
         double list[] = { 20.2, 20.7, 26.6, 17.7, 16.5, 46.7, 67.6, 90.0, 90.0 };
         double rot[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0};
         double z[] = { 0, 0, 0, 12, 46, 150, 169, 337, 400 };
    is it possible to initialise the data, not as is customarily done using something like this, with a 2x2 matrix:
    private Object[][] data = {
         {"Kathy", "Smith",
         "Snowboarding", new Integer(5), new Boolean(false)},
         {"John", "Doe",
         "Rowing", new Integer(3), new Boolean(true)},
         {"Sue", "Black",
         "Knitting", new Integer(2), new Boolean(false)},
         {"Jane", "White",
         "Speed reading", new Integer(20), new Boolean(true)},
         {"Joe", "Brown",
         "Pool", new Integer(10), new Boolean(false)}
    (Data taken from another website btw!)
    but by looping through the rows one by one and setting each one to the relevant array, eg. row 0 is timestep, row 1 is trim etc.?
    Many thanks
    Paul
    Edited by: 799615 on 09-Jan-2011 03:54

    I've tried something like this. See the pivot table mode here
    http://java-sl.com/envelope.html

  • JTable questions please help

    Ok my first question will be:
    I have written a class containing two JTables which is below:
    import javax.swing.JTable;
    import java.awt.Dimension;
    import javax.swing.table.AbstractTableModel;
    public class TableSetup {
         JTable wageTable;
         JTable categoryTable;
         public TableSetup()
               String[] columnNames = {"Wage",
                     "Hours",
                     "Gross Pay",
                     "Taxes",
                     "Net Pay"};
                Object[][] data = {
                          {new Float(14.12), new Integer(20),
                           new Float(282.40),  new Float(84.72),new Float(197.68)},
                           {new Float(14.12), new Integer(40),
                                new Float(564.80),  new Float(169.44),new Float(395.36)},
                                {new Float(14.12), new Integer(80),
                                     new Float(1129.60),  new Float(338.88),new Float(790.72)}
                wageTable = new JTable(data,columnNames);
                String[] columnNames2 = {"Categories",
                          "Percentage",
                          "Dollar Amount(20 Hours)",
                          "Dollar Amount(40 Hours)",
                          "Dollar Amount(80 Hours)",
                          "Net Pay"};
                Object[][] data2 =  {
                          {new String("Food"), new String(" "),
                                new String(" "),  new String(" "),new String(" "), new String(" ")},
                                {new String("Gasoline"), new String(" "),
                                     new String(" "),  new String(" "), new String(" "), new String(" "), new String(" ")},
                                     {new String("Savings"), new String(" "),
                                          new String(" "),  new String(" "),new String(" "), new String(" "), new String(" ")},
                                          {new String("Entertainment"), new String(" "),
                                               new String(" "),  new String(" "),new String(" "), new String(" "), new String(" ")},
                                               {new String("Miscellaneous"), new String(" "),
                                                    new String(" "),  new String(" "),new String(" "), new String(" "), new String(" ")},
                                                    {new String("Misc Savings"), new String(" "),
                                                         new String(" "),  new String(" "),new String(" "), new String(" "), new String(" ")}
                categoryTable = new JTable(data2,columnNames2);
               // wageTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
    }I instantiate it globally in my graphic drawing class like this:
    TableSetup setup = new TableSetup();Then I add a listener to them in the constructor like this:
    setup.wageTable.getModel().addTableModelListener(this);
         setup.categoryTable.getModel().addTableModelListener(this);And I want to use the tableChanged function:
    public void tableChanged(TableModelEvent e) {
        }What I want to do is have a separate things happen depending on which of the two table are being changed.
    My question is how do I distinguish between whether the "setup.wageTable" is being changed or the "setup.categoryTable" is being changed so I can code the two separate conditions depending on which table is being changed.
    Please continue to check this thread because I'm going to have more questions later.
    Thanks in advanced.
    Edited by: translore on Aug 22, 2008 11:24 PM
    Edited by: translore on Aug 22, 2008 11:26 PM

    translore wrote:
    My question is how do I distinguish between whether the "setup.wageTable" is being changed or the "setup.categoryTable" is being changed so I can code the two separate conditions depending on which table is being changed.
    Have two separate listeners. You can use inner classes or anonymous classes for the listeners - https://java.sun.com/docs/books/tutorial/java/javaOO/nested.html .

  • Jlist / JScrollPane simple question

    Hi all.
    I have a question in general about JList, and in particular about this simple code. The code sets up a list in which the first entry is too long for the width I want the list to be. Is there any way at all to get it to wrap lines? Even if it made that one entry several lines? Would JList be able to handle that at all? Note: I can't make this a JApplet because I want to include this in some larger code that stops working if it's a JApplet. Don't know if that means anything.
    Any help at all is appreciated. If you need clarification, I am happy to try to provide it. I'm a total n00b so you go ahead and patronize me.
       import javax.swing.*;
       import java.awt.*;
       import java.awt.event.*;
       public class StreamsApplet extends java.applet.Applet implements ActionListener {
          private static final String CHARSET = "UTF-8";
          Button add;
          Button remove;
          JList list;
          private DefaultListModel listModel;
          public void init() {
            listModel = new DefaultListModel();
            listModel.addElement("Debbie Scott blablablablablablablablablabla");
            listModel.addElement("Scott Hommel");
            listModel.addElement("Sharon Zakhour");
            listModel.addElement("Debbie Scott");
            listModel.addElement("Scott Hommel");
            listModel.addElement("Sharon Zakhour");
            listModel.addElement("Debbie Scott");
            listModel.addElement("Scott Hommel");
            listModel.addElement("Sharon Zakhour");
            listModel.addElement("Debbie Scott");
            listModel.addElement("Scott Hommel");
            listModel.addElement("Sharon Zakhour");
            listModel.addElement("Debbie Scott");
            listModel.addElement("Scott Hommel");
            listModel.addElement("Sharon Zakhour");
            list = new JList(listModel);
            list.setSelectionMode(
              ListSelectionModel.SINGLE_SELECTION);
            JScrollPane pane = new JScrollPane(list);
            add(pane, BorderLayout.CENTER);
            add = new Button("To 10");
            remove = new Button("To 2");
            JPanel bottomPanel = new JPanel();
            bottomPanel.add(add);
            bottomPanel.add(remove);
            add(bottomPanel, BorderLayout.SOUTH);
            add.addActionListener(this);
            remove.addActionListener(this);
              public void actionPerformed(ActionEvent e) {
                   if (e.getSource() == add)
                     list.setSelectedIndex(10);
              list.ensureIndexIsVisible(10);
              if (e.getSource() == remove)
                   list.setSelectedIndex(2);
                   list.ensureIndexIsVisible(2);
    }

    Everything you need to know, you can find right here:
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

  • MS Access and JTable Question......

    I have a MS Access Database file and I want to display the data on my JTable using JDBC/ODBC connectivity? Is this possible? how would the coding be like? Does anyone have a similar example?

    try,
    http://www.geocities.com/rmlchan/dba.html

  • JTable question

    I'm implementing the code from Manning's Swing book. The table is rendered correctly but the table model is not saving the edit changes. After a sort or save to a file, I don't see the changes made in the cells. The table is getting refreshed properly though. Can anyone <b> please help</b> ?
    <pre>
    package trunkxref;
    * Copyright 1999-2002 Matthew Robinson and Pavel Vorobiev.
    * All Rights Reserved.
    * ===================================================
    * This program contains code from the book "Swing"
    * 2nd Edition by Matthew Robinson and Pavel Vorobiev
    * http://www.spindoczine.com/sbe
    * ===================================================
    * The above paragraph must be included in full, unmodified
    * and completely intact in the beginning of any source code
    * file that references, copies or uses (in any way, shape
    * or form) code contained in this file.
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.text.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.net.*;
    public class trnk extends JFrame
    protected JTable m_table;
    protected TrunkReportData m_data;
    public InputStream is;
         Image imginsert, imgdel, imgup, imgdown, imgsav;
    URL jspURL;
    public trnk ( InputStream is, Image imginsert, Image imgdel, Image imgup, Image imgdown, Image imgsav, URL jspURL)
    super ("Trunks Data");
    setSize (600, 300);
         this.is=is;
         this.imginsert=imginsert;
         this.imgdel=imgdel;
         this.imgup=imgup;
         this.imgsav=imgsav;
         this.imgdown=imgdown;
         this.jspURL=jspURL;
    m_data = new TrunkReportData (this,imgup, imgdown);
    m_table = new JTable ();
    m_table.setAutoCreateColumnsFromModel (false);
    m_table.setModel (m_data);
    m_table.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
    for (int k = 0; k < m_data.getColumnCount (); k++)
         TableCellRenderer renderer = null;
         TableCellEditor editor = null;
         renderer = new TextAreaCellRenderer ();     // NEW
         editor = new TextAreaCellEditor ();
         TableColumn column = new TableColumn (k,
              TrunkReportData.m_columns[k].m_width,
                             renderer, editor);
         column.setHeaderRenderer(createDefaultRenderer());
         m_table.addColumn (column);
    JTableHeader header = m_table.getTableHeader ();
    header.setUpdateTableInRealTime (true);
         header.addMouseListener(new ColumnListener());
    header.setReorderingAllowed(true);
    JScrollPane ps = new JScrollPane ();
    ps.getViewport ().setBackground (m_table.getBackground ());
    ps.setSize (550, 150);
    ps.getViewport ().add (m_table);
    getContentPane ().add (ps, BorderLayout.CENTER);
    JToolBar tb = createToolbar ();
    getContentPane ().add (tb, BorderLayout.NORTH);
    JPanel p = new JPanel (new GridLayout (1, 2, 5, 5));
    getContentPane ().add (p, BorderLayout.SOUTH);
    protected TableCellRenderer createDefaultRenderer() {
    DefaultTableCellRenderer label = new DefaultTableCellRenderer()
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (table != null) {
    JTableHeader header = table.getTableHeader();
    if (header != null) {
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
    setText((value == null) ? "" : value.toString()) ;
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    return this;
    label.setHorizontalAlignment(JLabel.CENTER);
    return label;
    protected JToolBar createToolbar ()
    JToolBar tb = new JToolBar ();
    tb.setFloatable (false);
    JButton bt = new JButton (new ImageIcon (imginsert));
    //JButton bt = new JButton ("Insert");
    bt.setToolTipText ("Insert Row");
    bt.setRequestFocusEnabled (false);
    ActionListener lst = new ActionListener (){
    public void actionPerformed (ActionEvent e) {
         int nRow = m_table.getSelectedRow() + 1;
         m_data.insert (nRow);
         m_table.tableChanged (new TableModelEvent
         (m_data, nRow, nRow, TableModelEvent.ALL_COLUMNS,
         TableModelEvent.INSERT));
         m_table.setRowSelectionInterval (nRow, nRow);
    bt.addActionListener ((ActionListener)lst);
    tb.add (bt);
    bt = new JButton (new ImageIcon (imgdel));
    //bt = new JButton ("Delete");
    bt.setToolTipText("Delete Row");
    bt.setRequestFocusEnabled(false);
    lst = new ActionListener ()
         public void
         actionPerformed
         (ActionEvent e)
         int nRow = m_table.getSelectedRow();
         if (m_data.delete (nRow))
              m_table.tableChanged
              (new TableModelEvent
              (m_data, nRow, nRow,
              TableModelEvent.ALL_COLUMNS,
              TableModelEvent.DELETE));
              m_table.clearSelection();
         bt.addActionListener(lst);
         tb.add (bt);
    bt = new JButton (new ImageIcon (imgsav));
    //bt = new JButton ("Save");
    bt.setToolTipText("Save");
    bt.setRequestFocusEnabled(false);
    lst = new ActionListener ()
         public void
         actionPerformed
         (ActionEvent e)
         m_table.tableChanged (new TableModelEvent
         (m_data));
              //m_data.fireTableDataChanged();
              System.out.println("beginning to write data to" + jspURL.toString());
              //code to save data to file
              String txt="";
              Enumeration enum=m_data.m_vector.elements();
              while(enum.hasMoreElements())
                   TrunkData trnk = (TrunkData)enum.nextElement();
                   txt += trnk.m_sysname + " , "
                        + trnk.m_clli + " , "
                        + trnk.m_tg + " , "
                        + trnk.m_member.intValue() + " , "
                        + trnk.m_trunk_type + " , "
                        + trnk.m_lata + " , "
                        + trnk.m_lata_name + " , "
                        + trnk.m_prospect_server + " , "
                        + trnk.m_tgroupid + " , "
                        + trnk.m_ctg + " , "
                        + trnk.m_augmen.intValue() + " , "
                        + trnk.m_vendor + "\n";
              try {
              URLConnection jspCon=jspURL.openConnection();
              jspCon.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
              jspCon.setUseCaches(false);
              jspCon.setDoOutput(true);
              PrintStream out = new PrintStream(jspCon.getOutputStream());
              String postData= "Text=" + URLEncoder.encode(txt, "UTF-8");
              out.println(postData);
              out.flush();
              out.close();
              InputStreamReader in=new InputStreamReader(jspCon.getInputStream());
              int chr;
              while((chr=in.read()) != -1) {}
              in.close();
              } catch (Exception e2) {
                   System.out.println (" exception in writing data out "
                   + e2.toString());
              System.out.println("done write data");
         bt.addActionListener(lst);
         tb.add (bt);
         return tb;
         // NEW
         class ColumnListener extends MouseAdapter {
              public void mouseClicked(MouseEvent e) {
         m_table.tableChanged (new TableModelEvent
         (m_data));
                   //m_data.fireTableDataChanged();
                   TableColumnModel colModel = m_table.getColumnModel();
                   int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
                   int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
                   if (modelIndex < 0)
                        return;
                   if (m_data.m_sortCol == modelIndex)
                        m_data.m_sortAsc = !m_data.m_sortAsc;
                   else
                        m_data.m_sortCol = modelIndex;
                   for (int i=0; i < m_data.getColumnCount(); i++) {
                        TableColumn column = colModel.getColumn(i);
                        int index = column.getModelIndex();
                        JLabel renderer = (JLabel)column.getHeaderRenderer();
                        renderer.setIcon(m_data.getColumnIcon(index));
                   m_table.getTableHeader().repaint();
                   m_data.sortData();
                   m_table.tableChanged(new TableModelEvent(m_data));
                   m_table.repaint();
    class TextAreaCellRenderer extends JTextArea implements TableCellRenderer
    protected static Border m_noFocusBorder = new
    EmptyBorder (1,          1,          1,          1);
    protected static Border m_focusBorder =
    UIManager.getBorder("Table.focusCellHighlightBorder");
    public
    TextAreaCellRenderer
    setEditable
         (false);
    setLineWrap
         (true);
    setWrapStyleWord
         (true);
    setBorder
         (m_noFocusBorder);}
    public Component
    getTableCellRendererComponent
    (JTable table,
    Object value,
    boolean
    isSelected,
    boolean
    hasFocus,
    int nRow, int nCol)
    if (value     instanceof     String)
         setText ((String) value);
         else if (value instanceof Integer)
         setText((String)value.toString());
    setBackground
         (isSelected && !hasFocus ?     table.getSelectionBackground() : table.getBackground ());
    setForeground
         (isSelected
         && !hasFocus ?
         table.getSelectionForeground() : table.getForeground ());
    setFont (table.getFont ());
    setBorder (hasFocus ? m_focusBorder : m_noFocusBorder);
    // Adjust row's
    // height
    int width =
         table.getColumnModel().getColumn(nCol).getWidth ();
    setSize (width,
         1000);
    int rowHeight =     getPreferredSize().height;
    if (table.getRowHeight(nRow) != rowHeight)
         table.setRowHeight (nRow, rowHeight);
    return this;}
    // To fix JDK bug
    public String getToolTipText (MouseEvent event)
    return null;
    // NEW
    class TextAreaCellEditor extends AbstractCellEditor implements
    TableCellEditor
    public static int CLICK_COUNT_TO_EDIT = 1;
    protected JTextArea m_textArea;
    protected JScrollPane m_scroll;
    public TextAreaCellEditor ()
         m_textArea = new JTextArea ();
         m_textArea.setLineWrap (true);
         m_textArea.setWrapStyleWord (true);
         m_scroll = new JScrollPane (m_textArea,
         //JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
         JScrollPane.VERTICAL_SCROLLBAR_NEVER,
         //JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
         JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    public Component
    getTableCellEditorComponent
    (JTable table,
    Object value,
    boolean
    isSelected,
    int nRow, int nCol)
         m_textArea.setBackground(table.getBackground());
         m_textArea.setForeground(table.getForeground());
         m_textArea.setFont (table.getFont());
         m_textArea.setText (value == null ? "" : value.toString());
         return m_scroll;
    public Object getCellEditorValue ()
         return     m_textArea.getText ();
    public boolean isCellEditable (EventObject anEvent)
         if (anEvent instanceof     MouseEvent)
         int click = ((MouseEvent) anEvent).getClickCount();
         return click >= CLICK_COUNT_TO_EDIT;
         return true;
    class TrunkData
    public String m_sysname;
    public String m_clli;
    public String m_tg;
    public Integer m_member;
    public String m_trunk_type;
    public String m_lata;
    public String m_lata_name;
    public String m_prospect_server;
    public String m_tgroupid;
    public String m_ctg;
    public Integer m_augmen;
    public String m_vendor;
    public TrunkData ()
    m_sysname = "";
    m_clli = "";
    m_tg = "";
    m_member =     new Integer (0);
    m_trunk_type =     "";
    m_lata = "";
    m_lata_name =     "";
    m_prospect_server     = "";
    m_tgroupid = "";
    m_ctg = "";
    m_augmen = new Integer(0);
    m_vendor = "";
    public
    TrunkData
    (String sys,
    String clli,
    String tg,
    String member,
    String ttyp,
    String lata,
    String latanm,
    String pserver,
    String tgrpid,
    String ctg,
    String aug,
    String vend)
    m_sysname = sys;
    m_clli = clli;
    m_tg = tg;
         try {
         if (member.trim().equals(""))
         m_member=new Integer(0);
         else
    m_member =     new Integer(member.trim());
         } catch (Exception e) {
              System.out.println("can't parse member " + e.toString());
    m_trunk_type =     ttyp;
    m_lata = lata;
    m_lata_name =     latanm;
    m_prospect_server     = pserver;
    m_tgroupid =     tgrpid;
    m_ctg = ctg;
         if (aug.trim().equals(""))
         m_augmen=new Integer(0);
         else m_augmen=new Integer(aug.trim());
    m_vendor = vend;
    class ColumnData
    public String m_tolatLbl;
    int m_width;
    int m_alignment;
    public ColumnData (String title, int width, int alignment)
    m_tolatLbl =     title;
    m_width = width;
    m_alignment =     alignment;
    class TrunkReportData extends AbstractTableModel
    public static ImageIcon COLUMN_UP;
    public static ImageIcon COLUMN_DOWN;
    public int m_sortCol = 0;
    public boolean m_sortAsc = true;
    public static final ColumnData m_columns[] =
    new ColumnData ("System", 200, JLabel.LEFT),
    new ColumnData ("CLLI", 200, JLabel.LEFT),
    new ColumnData ("Trunk Group", 200, JLabel.LEFT),
    new ColumnData ("Members", 200, JLabel.LEFT),
    new ColumnData ("Trunk Type", 200, JLabel.LEFT),
    new ColumnData ("LATA ", 200, JLabel.LEFT),
    new ColumnData ("LATA Name", 200, JLabel.LEFT),
    new ColumnData ("Prospect Server", 200, JLabel.LEFT),
    new ColumnData ("Trunk Group ID", 200, JLabel.LEFT),
    new ColumnData ("CTG", 200, JLabel.LEFT),
    new ColumnData ("Augments", 200, JLabel.LEFT),
    new ColumnData ("Vendor", 200, JLabel.LEFT)
    protected trnk m_parent;
    protected Vector m_vector;
    public TrunkReportData (trnk parent , Image imgup, Image imgdown)
         this.COLUMN_UP=new ImageIcon(imgup);
         this.COLUMN_DOWN=new ImageIcon(imgdown);
    m_parent = parent;
    m_vector = new Vector ();
    setDefaultData (parent.is);
    public void setDefaultData (InputStream is)
    m_vector = new Vector ();
    int numFields =     0;
    try
    BufferedReader
         br =new     BufferedReader(new InputStreamReader(is));
    String inline ="";
    while ((inline = br.readLine()) != null)
         if (inline.indexOf('#') > -1)
         continue;
         StringTokenizer st = new StringTokenizer (inline, ",");
         String nsys=st.nextToken ().trim(); //sys
         String nclli= st.nextToken().trim() ;     // clli
         String ntg= st.nextToken ().trim();     // tg
         String nmemb= st.nextToken().trim();     // members
         String nttyp= st.nextToken ().trim();     // trunktype
         String nlata= st.nextToken ().trim();     // lata
         String nlataname= st.nextToken ().trim();     // lata name
         String npros= st.nextToken ().trim();     // prospect server
         String ntgrpid=st.nextToken().trim();      //tgroupid
         String nctg=st.nextToken().trim();      //ctg
         String naug=st.nextToken().trim();      //augments
         String nvend=st.nextToken().trim();      //vendor
         m_vector.addElement(new TrunkData(nsys,nclli, ntg,
              nmemb, nttyp, nlata, nlataname, npros, ntgrpid, nctg,
              naug,nvend));
    br.close ();}
    catch (Exception e)
    System.out.println("Error in file reader 2 "+ e.toString ());
         sortData();
    public Icon getColumnIcon(int column) { // NEW
    if (column==m_sortCol)
    return m_sortAsc ? COLUMN_UP : COLUMN_DOWN;
    return null;
    // NEW
    public void sortData() {
    Collections.sort(m_vector, new
    TrunkComparator(m_sortCol, m_sortAsc));
    public int getRowCount ()
    return m_vector == null ? 0 : m_vector.size ();
    public int getColumnCount ()
    return m_columns.length;
    public String getColumnName(int nCol)
    return m_columns[nCol]. m_tolatLbl;
    public boolean isCellEditable
    (int nRow, int nCol)
    return true;
    public Object getValueAt (int     nRow,     int nCol)
    if (nRow < 0 || nRow >=getRowCount())
    return "";
    TrunkData row = (TrunkData) m_vector.elementAt(nRow);
    switch (nCol)
    case 0:
    return row.m_sysname;
    case 1:
    return row.m_clli;
    case 2:
    return row.m_tg;
    case 3:
    return row.m_member;
    case 4:
    return row.m_trunk_type;
    case 5:
    return row.m_lata;
    case 6:
    return row.m_lata_name;
    case 7:
    return row.m_prospect_server;
    case 8:
    return row.m_tgroupid;
    case 9:
    return row.m_ctg;
    case 10:
    return row.m_augmen;
    case 11:
    return row.m_vendor;
    return "";
    public void setValueAt (Object value, int nRow, int nCol)
    if (nRow < 0
    || nRow >=
    getRowCount
    || value ==
    null)
    return;
    System.out.println("setting nrow=" + nRow + " nCol=" + nCol + " to value=" + (String) value);
    TrunkData row = (TrunkData) m_vector.elementAt (nRow);
    String svalue = value.toString ();
    switch (nCol)
    case 0:
    row.m_sysname = svalue; break;
    case 1:
    row.m_clli = svalue; break;
    case 2:
    row.m_tg = svalue; break;
    case 3:
         if (svalue.trim().equals(""))
         row.m_member=new Integer(0);
         else
    row.m_member = new Integer(svalue.trim()); break;
    case 4:
    row.m_trunk_type = svalue; break;
    case 5:
    row.m_lata = svalue; break;
    case 6:
    row.m_lata_name = svalue; break;
    case 7:
    row.m_prospect_server = svalue; break;
    case 8:
    row.m_tgroupid = svalue; break;
    case 9:
    row.m_ctg = svalue; break;
    case 10:
    row.m_augmen = new Integer(svalue.trim()); break;
    case 11:
    row.m_vendor = svalue; break;}
         fireTableCellUpdated(nRow,nCol);
    public void insert (int nRow)
    if (nRow < 0)
    nRow = 0;
    if (nRow >     m_vector.size ())
    nRow =
    m_vector. size ();
    m_vector.insertElementAt
    (new
    TrunkData (),
    nRow);
    public boolean delete (int nRow)
    if (nRow < 0
    || nRow >=
    m_vector.size
    ())return
         false;
    m_vector.remove (nRow);
    return true;
    class TrunkComparator implements Comparator {
         protected int m_sortCol;
    protected boolean m_sortAsc;
    public TrunkComparator(int sortCol, boolean sortAsc) {
    m_sortCol = sortCol;
    m_sortAsc = sortAsc;
         public int compare(Object o1, Object o2)
              if (!(o1 instanceof TrunkData) || !(o2 instanceof TrunkData))
              return 0;
              TrunkData s1=(TrunkData)o1;
              TrunkData s2=(TrunkData)o2;
              int result=0;
              String str1="", str2="";
              int i1=0, i2=0;
              switch(m_sortCol) {
                   case 0: //sysname
                   str1=(String)s1.m_sysname;
                   str2=(String)s2.m_sysname;
                   result=str1.compareTo(str2);
                   break;
                   case 1: // clli
                   str1=(String)s1.m_clli;
                   str2=(String)s2.m_clli;
                   result=str1.compareTo(str2);
                   break;
                   case 2: //TG
                   str1=(String)s1.m_tg;
                   str2=(String)s2.m_tg;
                   result=str1.compareTo(str2);
                   break;
                   case 3: //member
                   i1 =s1.m_member.intValue();
                   i2 =s2.m_member.intValue();
                   result = i1 < i2 ? -1 : (i1 > i2 ? 1 : 0);
                   break;
                   case 4: //trunk type
                   str1=(String)s1.m_trunk_type;
                   str2=(String)s2.m_trunk_type;
                   result=str1.compareTo(str2);
                   break;
                   case 5: //lata
                   str1=(String)s1.m_lata;
                   str2=(String)s2.m_lata;
                   result=str1.compareTo(str2);
                   break;
                   case 6: //lata name
                   str1=(String)s1.m_lata_name;
                   str2=(String)s2.m_lata_name;
                   result=str1.compareTo(str2);
                   break;
                   case 7: //prospect server
                   str1=(String)s1.m_prospect_server;
                   str2=(String)s2.m_prospect_server;
                   result=str1.compareTo(str2);
                   break;
                   case 8: //tgroup id
                   str1=(String)s1.m_tgroupid;
                   str2=(String)s2.m_tgroupid;
                   result=str1.compareTo(str2);
                   break;
                   case 9: //ctg
                   str1=(String)s1.m_ctg;
                   str2=(String)s2.m_ctg;
                   result=str1.compareTo(str2);
                   break;
                   case 10: //augments
                   i1 =s1.m_augmen.intValue();
                   i2 =s2.m_augmen.intValue();
                   result = i1 < i2 ? -1 : (i1 > i2 ? 1 : 0);
                   break;
                   case 11: //vendor
                   str1=(String)s1.m_vendor;
                   str2=(String)s2.m_vendor;
                   result=str1.compareTo(str2);
                   break;
         if (!m_sortAsc) result = -result;
         return result;
         public boolean equals(Object obj) {
              if (obj instanceof TrunkComparator) {
                   TrunkComparator compObj=(TrunkComparator) obj;
                   return (compObj.m_sortCol == m_sortCol) &&
                        (compObj.m_sortAsc==m_sortAsc);
              return false;
    </pre>

    Sorry about the code mess. I'm trying to use the JFrame inside an applet. Is there some way to make the applet show up inside the browser instead of as a separate window as it is doing now? I've searched through the posts in this forum without much result. I gleaned this from jguru.com but don't know how to implement:
    If you would like to have Frames appear in the web page itself, you could add a JDesktopPane to a JApplet, and add JInternalFrames to it. This of course requires Swing, and the best way to ensure this is to use the Java Plug-in from Sun (http://java.sun.com/products/plugin/).
    I want to use Tab key to move between cells. I've researched that matter in this forum but don't have a good solution yet. Please help .
    package trunkxref;
    *  Copyright 1999-2002 Matthew Robinson and Pavel Vorobiev.
    *  All Rights Reserved.
    *  ===================================================
    *  This program contains code from the book "Swing"
    *  2nd Edition by Matthew Robinson and Pavel Vorobiev
    *  http://www.spindoczine.com/sbe
    *  ===================================================
    *  The above paragraph must be included in full, unmodified
    *  and completely intact in the beginning of any source code
    *  file that references, copies or uses (in any way, shape
    *  or form) code contained in this file.
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.text.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.net.*;
    public class trnk extends JFrame
      protected JTable m_table;
      protected TrunkReportData m_data;
      public InputStream is;
         Image imginsert, imgdel, imgup, imgdown, imgsav;
      URL jspURL;
      public trnk ( InputStream is, Image imginsert, Image imgdel, Image imgup, Image imgdown, Image imgsav, URL jspURL)
        super ("Trunks Data");
        setSize (600, 300);
         this.is=is;
         this.imginsert=imginsert;
         this.imgdel=imgdel;
         this.imgup=imgup;
         this.imgsav=imgsav;
         this.imgdown=imgdown;
         this.jspURL=jspURL;
        m_data = new TrunkReportData (this,imgup, imgdown);
        m_table = new JTable ();
        m_table.setAutoCreateColumnsFromModel (false);
        m_table.setModel (m_data);
        m_table.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
        for (int k = 0; k < m_data.getColumnCount (); k++)
         TableCellRenderer renderer = null;
         TableCellEditor editor = null;
         renderer = new TextAreaCellRenderer ();     // NEW
         editor = new TextAreaCellEditor ();
         TableColumn column = new TableColumn (k,
              TrunkReportData.m_columns[k].m_width,
                                   renderer, editor);
         column.setHeaderRenderer(createDefaultRenderer());
         m_table.addColumn (column);
        JTableHeader header = m_table.getTableHeader ();
        header.setUpdateTableInRealTime (true);
         header.addMouseListener(new ColumnListener());
            header.setReorderingAllowed(true);
        JScrollPane ps = new JScrollPane ();
        ps.getViewport ().setBackground (m_table.getBackground ());
        ps.setSize (550, 150);
        ps.getViewport ().add (m_table);
        getContentPane ().add (ps, BorderLayout.CENTER);
        JToolBar tb = createToolbar ();
        getContentPane ().add (tb, BorderLayout.NORTH);
        JPanel p = new JPanel (new GridLayout (1, 2, 5, 5));
        getContentPane ().add (p, BorderLayout.SOUTH);
    protected TableCellRenderer createDefaultRenderer() {
          DefaultTableCellRenderer label = new DefaultTableCellRenderer()
                    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                                   if (table != null) {
                                     JTableHeader header = table.getTableHeader();
                                            if (header != null) {
                                                setForeground(header.getForeground());
                                                setBackground(header.getBackground());
                                                    setFont(header.getFont());
                                    setText((value == null) ? "" : value.toString()) ;
                                  setBorder(UIManager.getBorder("TableHeader.cellBorder"));
                                    return this;
                    label.setHorizontalAlignment(JLabel.CENTER);
                    return label;
      protected JToolBar createToolbar ()
        JToolBar tb = new JToolBar ();
        tb.setFloatable (false);
        JButton bt = new JButton (new ImageIcon (imginsert));
        //JButton bt = new JButton ("Insert");
        bt.setToolTipText ("Insert Row");
        bt.setRequestFocusEnabled (false);
        ActionListener lst = new ActionListener (){
           public void actionPerformed (ActionEvent e) {
         int nRow = m_table.getSelectedRow() + 1;
         m_data.insert (nRow);
         m_table.tableChanged (new TableModelEvent
            (m_data, nRow, nRow, TableModelEvent.ALL_COLUMNS,
             TableModelEvent.INSERT));
         m_table.setRowSelectionInterval (nRow, nRow);
        bt.addActionListener ((ActionListener)lst);
        tb.add (bt);
        bt = new JButton (new ImageIcon (imgdel));
        //bt = new JButton ("Delete");
        bt.setToolTipText("Delete Row");
        bt.setRequestFocusEnabled(false);
        lst = new ActionListener ()
         public void
           actionPerformed
           (ActionEvent e)
             int nRow = m_table.getSelectedRow();
             if (m_data.delete (nRow))
              m_table.tableChanged
                (new TableModelEvent
                 (m_data, nRow, nRow,
                  TableModelEvent.ALL_COLUMNS,
                  TableModelEvent.DELETE));
              m_table.clearSelection();
         bt.addActionListener(lst);
         tb.add (bt);
        bt = new JButton (new ImageIcon (imgsav));
        //bt = new JButton ("Save");
        bt.setToolTipText("Save");
        bt.setRequestFocusEnabled(false);
        lst = new ActionListener ()
         public void
           actionPerformed
           (ActionEvent e)
         m_table.tableChanged (new TableModelEvent
            (m_data));
              //m_data.fireTableDataChanged();
              System.out.println("beginning to write data to" + jspURL.toString());
              //code to save data to file
              String txt="";
              Enumeration enum=m_data.m_vector.elements();
              while(enum.hasMoreElements())
                   TrunkData trnk = (TrunkData)enum.nextElement();
                   txt += trnk.m_sysname + " , "
                        + trnk.m_clli + " , "
                        + trnk.m_tg + " , "
                        + trnk.m_member.intValue() + " , "
                        + trnk.m_trunk_type + " , "
                        + trnk.m_lata + " , "
                        + trnk.m_lata_name + " , "
                        + trnk.m_prospect_server + " , "
                        + trnk.m_tgroupid + " , "
                        + trnk.m_ctg + " , "
                        + trnk.m_augmen.intValue() + " , "
                        + trnk.m_vendor + "\n";
              try {
              URLConnection jspCon=jspURL.openConnection();
              jspCon.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
              jspCon.setUseCaches(false);
              jspCon.setDoOutput(true);
              PrintStream out = new PrintStream(jspCon.getOutputStream());
              String postData= "Text=" + URLEncoder.encode(txt, "UTF-8");
              out.println(postData);
              out.flush();
              out.close();
              InputStreamReader in=new InputStreamReader(jspCon.getInputStream());
              int chr;
              while((chr=in.read()) != -1) {}
              in.close();
              } catch (Exception e2) {
                   System.out.println (" exception in writing data out "
                   + e2.toString());
              System.out.println("done write data");
         bt.addActionListener(lst);
         tb.add (bt);
         return tb;
         // NEW
         class ColumnListener extends MouseAdapter {
              public void mouseClicked(MouseEvent e) {
         m_table.tableChanged (new TableModelEvent
            (m_data));
                   //m_data.fireTableDataChanged();
                   TableColumnModel colModel = m_table.getColumnModel();
                   int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
                   int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
                   if (modelIndex < 0)
                        return;
                   if (m_data.m_sortCol == modelIndex)
                        m_data.m_sortAsc = !m_data.m_sortAsc;
                   else
                        m_data.m_sortCol = modelIndex;
                   for (int i=0; i < m_data.getColumnCount(); i++) {
                        TableColumn column = colModel.getColumn(i);
                        int index = column.getModelIndex();
                        JLabel renderer = (JLabel)column.getHeaderRenderer();
                        renderer.setIcon(m_data.getColumnIcon(index));
                   m_table.getTableHeader().repaint();
                   m_data.sortData();
                   m_table.tableChanged(new TableModelEvent(m_data));
                   m_table.repaint();
      class TextAreaCellRenderer extends JTextArea implements TableCellRenderer
        protected static Border m_noFocusBorder    =    new
        EmptyBorder (1,           1,           1,           1);
        protected static    Border    m_focusBorder =
        UIManager.getBorder("Table.focusCellHighlightBorder");
        public
        TextAreaCellRenderer
          setEditable
         (false);
          setLineWrap
         (true);
          setWrapStyleWord
         (true);
          setBorder
         (m_noFocusBorder);}
        public Component
        getTableCellRendererComponent
        (JTable table,
         Object value,
         boolean
         isSelected,
         boolean
         hasFocus,
         int nRow, int nCol)
          if (value       instanceof       String)
         setText ((String) value);
         else if (value instanceof Integer)
         setText((String)value.toString());
          setBackground
         (isSelected && !hasFocus ?      table.getSelectionBackground() : table.getBackground ());
          setForeground
         (isSelected
          && !hasFocus ?
          table.getSelectionForeground() : table.getForeground ());
          setFont (table.getFont ());
          setBorder (hasFocus ? m_focusBorder : m_noFocusBorder);
          // Adjust row's
          // height
          int width =
         table.getColumnModel().getColumn(nCol).getWidth ();
          setSize (width,
                1000);
          int rowHeight =     getPreferredSize().height;
          if (table.getRowHeight(nRow) !=  rowHeight)
         table.setRowHeight (nRow,  rowHeight);
          return this;}
        // To fix JDK bug
        public String getToolTipText (MouseEvent event)
          return null;
      // NEW
      class TextAreaCellEditor extends AbstractCellEditor implements
      TableCellEditor
    public static int CLICK_COUNT_TO_EDIT = 1;
          protected JTextArea m_textArea;
        protected JScrollPane m_scroll;
        public TextAreaCellEditor ()
         m_textArea = new JTextArea ();
         m_textArea.setLineWrap (true);
         m_textArea.setWrapStyleWord (true);
         m_scroll = new JScrollPane (m_textArea,
            //JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.VERTICAL_SCROLLBAR_NEVER,
            //JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        public Component
          getTableCellEditorComponent
          (JTable table,
           Object value,
           boolean
           isSelected,
           int nRow, int nCol)
         m_textArea.setBackground(table.getBackground());
         m_textArea.setForeground(table.getForeground());
         m_textArea.setFont (table.getFont());
         m_textArea.setText (value   ==   null ?   "" :  value.toString());
         return m_scroll;
        public Object getCellEditorValue ()
         return       m_textArea.getText ();
        public boolean isCellEditable (EventObject anEvent)
         if (anEvent   instanceof         MouseEvent)
             int click = ((MouseEvent) anEvent).getClickCount();
             return click >= CLICK_COUNT_TO_EDIT;
         return true;
      class TrunkData
        public String    m_sysname;
        public String    m_clli;
        public String    m_tg;
        public Integer     m_member;
        public String    m_trunk_type;
        public String    m_lata;
        public String    m_lata_name;
        public String    m_prospect_server;
        public String    m_tgroupid;
        public String    m_ctg;
        public Integer   m_augmen;
        public String    m_vendor;
        public TrunkData ()
          m_sysname = "";
          m_clli = "";
          m_tg = "";
          m_member =     new Integer (0);
          m_trunk_type =     "";
          m_lata = "";
          m_lata_name =       "";
          m_prospect_server       = "";
          m_tgroupid = "";
          m_ctg = "";
          m_augmen = new Integer(0);
          m_vendor = "";
        public
        TrunkData
        (String sys,
         String clli,
         String tg,
         String member,
         String ttyp,
         String lata,
         String latanm,
         String pserver,
         String tgrpid,
         String ctg,
         String aug,
         String vend)
          m_sysname = sys;
          m_clli = clli;
          m_tg = tg;
         try {
         if (member.trim().equals(""))
         m_member=new Integer(0);
         else
          m_member =     new Integer(member.trim());
         } catch (Exception e) {
              System.out.println("can't parse member " + e.toString());
          m_trunk_type =     ttyp;
          m_lata = lata;
          m_lata_name =     latanm;
          m_prospect_server     = pserver;
          m_tgroupid =     tgrpid;
          m_ctg = ctg;
         if (aug.trim().equals(""))
         m_augmen=new Integer(0);
         else m_augmen=new Integer(aug.trim());
          m_vendor = vend;
      class ColumnData
        public String    m_tolatLbl;
        int m_width;
        int m_alignment;
        public    ColumnData    (String title,     int width,     int alignment)
          m_tolatLbl =     title;
          m_width = width;
          m_alignment =     alignment;
      class  TrunkReportData  extends  AbstractTableModel
    public static ImageIcon COLUMN_UP;
            public static ImageIcon COLUMN_DOWN;
        public int               m_sortCol = 0;
            public boolean m_sortAsc = true;
        public static      final ColumnData      m_columns[] =
          new      ColumnData      ("System", 200,       JLabel.LEFT),
          new      ColumnData      ("CLLI", 200,       JLabel.LEFT),
          new      ColumnData      ("Trunk Group",       200,       JLabel.LEFT),
          new      ColumnData      ("Members", 200,       JLabel.LEFT),
          new      ColumnData      ("Trunk Type",       200,       JLabel.LEFT),
          new      ColumnData      ("LATA ", 200,       JLabel.LEFT),
          new      ColumnData      ("LATA Name",       200,       JLabel.LEFT),
          new      ColumnData      ("Prospect Server",       200,       JLabel.LEFT),
          new      ColumnData      ("Trunk Group ID",       200,       JLabel.LEFT),
          new      ColumnData      ("CTG", 200,       JLabel.LEFT),
          new      ColumnData      ("Augments", 200,       JLabel.LEFT),
          new      ColumnData      ("Vendor", 200,       JLabel.LEFT)
        protected      trnk m_parent;
        protected Vector      m_vector;
        public TrunkReportData (trnk parent , Image imgup, Image imgdown)
         this.COLUMN_UP=new ImageIcon(imgup);
         this.COLUMN_DOWN=new ImageIcon(imgdown);
          m_parent = parent;
          m_vector = new Vector ();
          setDefaultData (parent.is);
        public void setDefaultData (InputStream is)
          m_vector =  new Vector ();
        int numFields =       0;
        try
          BufferedReader
         br =new     BufferedReader(new InputStreamReader(is));
          String inline ="";
          while ((inline =  br.readLine()) != null)
           if (inline.indexOf('#') > -1)
               continue;
           StringTokenizer st = new StringTokenizer (inline, ",");
           String nsys=st.nextToken ().trim(); //sys
           String nclli=  st.nextToken().trim() ;     // clli
           String ntg= st.nextToken ().trim();     // tg
           String nmemb=  st.nextToken().trim();     // members
           String nttyp=   st.nextToken ().trim();     // trunktype
           String nlata= st.nextToken ().trim();     // lata
           String nlataname=  st.nextToken ().trim();     // lata  name
           String npros=    st.nextToken ().trim();     // prospect  server
           String ntgrpid=st.nextToken().trim();      //tgroupid
           String nctg=st.nextToken().trim();      //ctg
           String naug=st.nextToken().trim();      //augments
           String nvend=st.nextToken().trim();      //vendor
            m_vector.addElement(new TrunkData(nsys,nclli, ntg,
              nmemb, nttyp, nlata, nlataname, npros, ntgrpid, nctg,
              naug,nvend));
          br.close ();}
        catch (Exception e)
          System.out.println("Error in file reader 2 "+ e.toString ());
         sortData();
    public Icon getColumnIcon(int column) { // NEW
                    if (column==m_sortCol)
                            return m_sortAsc ? COLUMN_UP : COLUMN_DOWN;
                    return null;
    // NEW
            public void sortData() {
                    Collections.sort(m_vector, new
                            TrunkComparator(m_sortCol, m_sortAsc));
    public int getRowCount ()
      return m_vector == null ? 0 : m_vector.size ();
    public int getColumnCount ()
      return    m_columns.length;
    public String getColumnName(int nCol)
      return    m_columns[nCol]. m_tolatLbl;
    public boolean isCellEditable
    (int nRow, int nCol)
      return true;
    public Object getValueAt (int         nRow,         int nCol)
      if (nRow < 0 || nRow >=getRowCount())
        return "";
      TrunkData row = (TrunkData) m_vector.elementAt(nRow);
      switch (nCol)
        case 0:
          return row.m_sysname;
        case 1:
          return row.m_clli;
        case 2:
          return row.m_tg;
        case 3:
          return row.m_member;
        case 4:
          return row.m_trunk_type;
        case 5:
          return row.m_lata;
        case 6:
          return row.m_lata_name;
        case 7:
          return row.m_prospect_server;
        case 8:
          return row.m_tgroupid;
        case 9:
          return row.m_ctg;
        case 10:
          return row.m_augmen;
        case 11:
          return row.m_vendor;
      return "";
    public void setValueAt (Object value, int nRow, int nCol)
      if (nRow < 0
          || nRow >=
          getRowCount
          || value ==
          null)
        return;
    System.out.println("setting nrow=" + nRow + " nCol=" + nCol + " to value=" + (String) value);
      TrunkData row = (TrunkData) m_vector.elementAt (nRow);
      String svalue = value.toString ();
      switch (nCol)
        case 0:
          row.m_sysname = svalue; break;
        case 1:
          row.m_clli = svalue; break;
        case 2:
          row.m_tg = svalue; break;
        case 3:
         if (svalue.trim().equals(""))
         row.m_member=new Integer(0);
         else
          row.m_member = new Integer(svalue.trim()); break;
        case 4:
          row.m_trunk_type = svalue; break;
        case 5:
          row.m_lata = svalue; break;
        case 6:
          row.m_lata_name = svalue; break;
        case 7:
          row.m_prospect_server = svalue; break;
        case 8:
          row.m_tgroupid = svalue; break;
        case 9:
          row.m_ctg = svalue; break;
        case 10:
          row.m_augmen = new Integer(svalue.trim()); break;
        case 11:
          row.m_vendor = svalue; break;}
         fireTableCellUpdated(nRow,nCol);
    public void insert (int nRow)
      if (nRow < 0)
        nRow = 0;
      if (nRow >     m_vector.size ())
        nRow  =
          m_vector. size ();
      m_vector.insertElementAt
        (new
         TrunkData (),
         nRow);
    public boolean delete (int nRow)
      if (nRow < 0
          || nRow >=
          m_vector.size
          ())return
            false;
      m_vector.remove (nRow);
      return true;
    class TrunkComparator implements Comparator {
          protected int            m_sortCol;
            protected boolean m_sortAsc;
            public TrunkComparator(int sortCol, boolean sortAsc) {
                    m_sortCol = sortCol;
                    m_sortAsc = sortAsc;
         public int compare(Object o1, Object o2)
              if (!(o1 instanceof TrunkData) || !(o2 instanceof TrunkData))
              return 0;
              TrunkData s1=(TrunkData)o1;
              TrunkData s2=(TrunkData)o2;
              int result=0;
              String str1="", str2="";
              int i1=0, i2=0;
              switch(m_sortCol) {
                   case 0: //sysname
                   str1=(String)s1.m_sysname;
                   str2=(String)s2.m_sysname;
                   result=str1.compareTo(str2);
                   break;
                   case 1: // clli
                   str1=(String)s1.m_clli;
                   str2=(String)s2.m_clli;
                   result=str1.compareTo(str2);
                   break;
                   case 2: //TG
                   str1=(String)s1.m_tg;
                   str2=(String)s2.m_tg;
                   result=str1.compareTo(str2);
                   break;
                   case 3: //member
                   i1 =s1.m_member.intValue();
                   i2 =s2.m_member.intValue();
                   result = i1 < i2 ? -1 : (i1 > i2 ? 1 : 0);
                   break;
                   case 4: //trunk type
                   str1=(String)s1.m_trunk_type;
                   str2=(String)s2.m_trunk_type;
                   result=str1.compareTo(str2);
                   break;
                   case 5: //lata
                   str1=(String)s1.m_lata;
                   str2=(String)s2.m_lata;
                   result=str1.compareTo(str2);
                   break;
                   case 6: //lata name
                   str1=(String)s1.m_lata_name;
                   str2=(String)s2.m_lata_name;
                   result=str1.compareTo(str2);
                   break;
                   case 7: //prospect server
                   str1=(String)s1.m_prospect_server;
                   str2=(String)s2.m_prospect_server;
                   result=str1.compareTo(str2);
                   break;
                   case 8: //tgroup id
                   str1=(String)s1.m_tgroupid;
                   str2=(String)s2.m_tgroupid;
                   result=str1.compareTo(str2);
                   break;
                   case 9: //ctg
                   str1=(String)s1.m_ctg;
                   str2=(String)s2.m_ctg;
                   result=str1.compareTo(str2);
                   break;
                   case 10: //augments
                   i1 =s1.m_augmen.intValue();
                   i2 =s2.m_augmen.intValue();
                   result = i1 < i2 ? -1 : (i1 > i2 ? 1 : 0);
                   break;
                   case 11: //vendor
                   str1=(String)s1.m_vendor;
                   str2=(String)s2.m_vendor;
                   result=str1.compareTo(str2);
                   break;
         if (!m_sortAsc) result = -result;
         return result;
         public boolean equals(Object obj) {
              if (obj instanceof TrunkComparator) {
                   TrunkComparator compObj=(TrunkComparator) obj;
                   return (compObj.m_sortCol == m_sortCol) &&
                        (compObj.m_sortAsc==m_sortAsc);
              return false;
    }

  • JTable questions

    Whats the easiest, fastest way to save the contents of a JTable to the hard drive, and then be able to load it back up again??
    Also, whats the fastest way to add and remove rows from a JTable. I want the user to be able to push (+) and (-) buttons to add and remove rows from a JTable.
    Any help would be GREATLY appreciated.
    Thanks,
    javab0y
    [email protected]

    Whats the easiest, fastest way to save the contents of
    a JTable to the hard drive, and then be able to load
    it back up again??I don't know about this part. What kind of application are you developing? Also let us know what is the need to do this? I am curious about this part.
    Also, whats the fastest way to add and remove rows
    from a JTable. I want the user to be able to push (+)
    and (-) buttons to add and remove rows from a JTable.for this part add two buttons with + and - symbols on them and then add ActionListeners to both of them.
    now you could do two things:
    1. add a row at the end
    2. insert at a specific position
    you could add event listeners to your table and then based on whether your option you can either add or delete the selected row.
    javax.swing.table.DefaultTableModel
    1. addRow
    2. insertRow
    3. deleteRow
    use these methods to incorporate these functionalities to your interface. hope this solves your problem.
    bol,
    npaila

  • JTable question (last edit before close problem)

    Hello all,
    I have a simple looking problem. It's a JTable inside a dialog, but I can't get exactly the behaviour I want, that is, when the user edits a cell and, without pressing enter or selecting another cell, clicks "OK" (and the dialog hides) the editing should end and the value that was entered to get to the model.
    If I show the dialog again, the editing of the cell is still there, and the value is not updated (neither of course shown with a cell renderer)
    How could I finish programmatically the editing of a cell, and the result be the same as the user pressed enter or so?
    Very very much thank u

    It seems I posted this too early, sorry!
    I found an answer in
    http://forum.java.sun.com/thread.jsp?forum=57&thread=204066

  • Simple JTable questions

    when a resultset returns 20 columns
    say column1, column2, ...column20.
    and if we need to diaplay
    column1, column7, column8, column19, column20
    how to do this.

    in otherwords, i am trying to find out if its possible to do like this.
    "6th column returned from a resultset should go in column2 in jtable",
    "6th column returned from a resultset should go in column1 in jtable"

Maybe you are looking for

  • Java.Lang.ClassCastException in HelloWorldMessageJNDI

    Hi I am getting this error message when I compile and run the Sun provided sample HelloWorldMessageJNDI Looking up Queue Connection Factory object with lookup name: MyQueueConnectionFactory Exception in thread "main" java.lang.ClassCastException at H

  • Problems assigning values via F4 or search help

    Hello After a system copy and upgrade we are having one main problem.(EBP 3 -> SRM 4) In all the attributes that have F4 search help function module based. The match-code appear wuth values but when you select a different value, this is not changed i

  • Locking Ztransaction

    Hi Experts,    i want to lock the ztransaction in change mode.i searched in sdn i came to know by using lock object i can lock it.i understood how to create lock object.which is generating two function modules.my question is how to use this function

  • Add user in ACS with limited access

    Dear I have low experiance with cisco ACS So kindly i need help to add user to The ACS which has limited access to my network Switches ( As Show only not to change configuration ) Also how to take backup for the ACS Database Thanks,

  • Spatial conform and blend mode; what does it mean and wherefore?

    I can't find a explination in the help...: spatial conform and blend mode; what does it mean and when do you use it because there is e a big numbre of choises. Ican't find a explination in the help... Thanks!