Regarding Jtable

Hi
I have created a jtable with default table model and rendered its first cell as a JButton with lable "+"
I have written an action listener for the button click event which does some action and set the label of the button "-" .
Its working well ,the action associated with the event is done but the button label is still "+"
I am able to see the chane in label only when the column is resized....
can please anyone help me out
its urgent
i want the button lable to be changed without resizing....
Thanks in advance
Rgrds
Sharmila

The renderer for a table cell is only a rubber stamp used to display the cell. It isn't a component placed on the screen. Changing the component (the button) doesn't make it display on the table. You have two problems. The first is that you need to get the button to redisplay. fireTableChanged() was a good idea, but it's really overkill. Try using fireTableCellChanged(int,int) (I think). Next, you need to get your button to know if it should display a '+' or '-'. That data needs to be stored somewhere (usually in the tablemodel). For example, your first column could be a Boolean in the tablemodel, but displayed as a button. Or your renderer could look at another column (table.getValue(row, othercolumn)) to see how it should display.
Buttons might not be a good idea in tables. You can't add a listener to them because they are just displayed (rubber stamp). You can use one, but the listener should be on the table, not the button.

Similar Messages

  • Urgent Regarding Jtable TAB and Arrow keys

    Hi guys and gals,
    In my project i need urgnet help regarding Jtable.I want to use DOWN ARROW key same as TAB function.When i reach the first row last editing coulmn by using arrow key,then i habe to creating a new row with default values.And if press UP key if that row contains no values i have to delete.Plz help me in this regard.
    sreeni

    I meant that the laptop freezes in gdm and in console (tty1). In gdm i can't even type any character. And in console i can login but when i press the tab key (autocompletation) it stops. The only thing i can do is press the power button.
    Actually my keymap is es_ES. And i think that it's working fine because the n tilde and pipes work fine.

  • Tricky Query regarding JTables.

    This is a bit tricky regarding JTables
    I have run the flwg query
    select id_status 'STATUS',id_entity 'ENTITY'
    from TableA
    group by id_status,id_entity
    Output
    STATUS ENTITY
    100      AGL
    123      BSS
    234      RDB
    245      GERI have now both the rows and cols in 2 vectors.
    The Output I want is this:
    Depending on the No.of entities displayed above,these then
    become the column headings and the 4 rows will be shown as one row:
    OUTPUT REQUIRED:
    Type   AGL   BSS   RDB   GER
    Files  100   123   234   245I am able to display the 4 entity names as columns names by :
    for ( int i = 0; i < rowCount; i++ ) {
      m_colName.add(stm.getValueAt(i,2) );  // Where m_colName is a vector.
    JTable table = new Table(m_rowName,m_colName);Now how do I read the data from the row Vector which now contains 4 rows
    as one row and display them
    This is my current row display (which is my current row display)
    for ( int i = 0; i < rowCount; i++ ) {
         m_rows    = new Vector();
         for ( int z = 0; z < colCount; z++ ) {
              m_rows.add(stm.getValueAt(i,z) );
         // Vector of vectors.
         m_rowValues.addElement(m_rows);
    }I may have to modify the above code so that the 4 rows are displayed as one row
    and displayed as discussed above.
    My present output is
    AGL   BSS  RDB  GER
    100
    123
    234
    245Please help me now to read the 4 rows as one row and display them.

    Wrong use of rows/columns. Try like below:
    for ( int i = 0; i < colCount; i++ ) {
         m_rows    = new Vector();
         for ( int z = 0; z < rowCount; z++ ) {
              m_rows.add(stm.getValueAt(i,z) );
         // Vector of vectors.
         m_rowValues.addElement(m_rows);
    }You weren't so far from it ;-)

  • Help regarding JTable in Java Swing

    hi,
    i m confused regarding JTable in Swing. i hav added a JTextField in a cell of a JTable. i hav attached a kay listener with that textfield . But when i m selecting that cell ,where i hav added that textfield with a single click and typeing any key i m not getting that keyevent. But when i m selecting the same with a doulbe click and typing any thing i m getting that event .
    can any one tell me why the discrepency taking place. that textfield is
    there in that cell .then how it does make any difference with a single and double click.
    regards

    i hav added a JTextField in a cell of a JTableYou don't add a text field to a cell in a table. You add a text String to the TableModel. When the user double clicks on the cell an 'editor' is invoked and the text is copied to the editor (which by default is a JTextField). So the KeyStrokes go to the editor text field.
    When you just single click on a cell the table still has focus, not the editor, to the KeyStroke character is passed directly to the text field without the text field actually getting focus.

  • Regarding JTable selection

    Hi,
    I did one non-editable JTable. If I press "F2" button on selected row of that table, It's throwing following exception on console. Please try to provide solution for me.
    Regards & Thanks,
    Sukumar
    java.lang.NullPointerException:
    at javax.swing.plaf.basic.BasicTableUI$3.actionPerformed(BasicTableUI.java:675)
    at javax.swing.JComponent.processKeyBinding(JComponent.java, Compiled Code)
    at javax.swing.JComponent.processKeyBindings(JComponent.java, Compiled Code)
    at javax.swing.JComponent.processKeyEvent(JComponent.java, Compiled Code)
    at java.awt.Component.processEvent(Component.java, Compiled Code)
    at java.awt.Container.processEvent(Container.java, Compiled Code)
    at java.awt.Component.dispatchEventImpl(Component.java, Compiled Code)
    at java.awt.Container.dispatchEventImpl(Container.java, Compiled Code)
    at java.awt.Component.dispatchEvent(Component.java, Compiled Code)
    at java.awt.LightweightDispatcher.processKeyEvent(Container.java, Compiled Code)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java, Compiled Code)
    at java.awt.Container.dispatchEventImpl(Container.java, Compiled Code)
    at java.awt.Window.dispatchEventImpl(Window.java, Compiled Code)
    at java.awt.Component.dispatchEvent(Component.java, Compiled Code)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java, Compiled Code)
    at java.awt.EventDispatchThread.pumpOneEventForComponent(EventDispatchThread.java, Compiled Code)
    at java.awt.EventDispatchThread.pumpEventsForComponent(EventDispatchThread.java:95)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:90)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

    A little busy to help people.
    But happy you found my posted message.
    http://forum.java.sun.com/thread.jsp?thread=137174&forum=57&message=1135327
    Still, I do not research how to unregister yet,
    but you can register "null" action.
    Good luck.

  • Need Help regarding JTable Sort?

    Hello friends, i am working on the JTable and want to sort it by clicking on header of the column. I am using jdk1.5 and as my project is based on it so i cant change the jdk. I dont have the rowsorter class in jdk 1.5. So Is there any way through which i can sort the the Jtable by clicking its column header.
    Thanks for any help.

    Here is a link to the 1.5 Swing tutorial:
    https://www.cs.auckland.ac.nz/references/java/java1.5/tutorial/uiswing/TOC.html
    The Table section has a sorting example.

  • Threads regarding JTable

    I want to add checkboxes to each cell of a row.in Jtable. At the same time I used DefaultTableModel to insert rows from database.
    Checkbox are implemented using, AbstarctTableModel.
    Can I use both these table models in one class?
    Edited by: DHURAI on Jul 29, 2009 3:07 AM

    Thank u for ur reply.
    TableColumn table = jTable1.getColumnModel().getColumn(2);
            table.setCellEditor(new DefaultCellEditor(Checkbox));I used the above code to add checkbox in cell of table. Instead of showing checkbox, it shows true or false.
    The checkbox arrives and disappears for mouse click only and the value true or false also gets changed. What I have to do, to retain the checkbox format as it, instead of text message as true/False?

  • Regarding setValueAt method in JTable

    sir,
    i have a problem regarding JTable.
    now if u enter the data in cell
    then setvalueAt() method is called once
    now if u enter the data in a cell which is already
    having a dat in that cell, then the setvalueAt method
    is called twice.........
    why it so and how can i prevent it as i needed it in
    getting dataVector and when i print the values of dataVactor
    it gives recent values not the previuos set values
    i m just beginner in this concern
    i hope u be able to understand and solve
    thanks in advance

    Hi,
    I have looked at your code. You are still trying to control too much yourself. Let the table do it instead. The table is designed to handle all of its events and works best when you let it. I made a few code suggestions here. I didn't compile it, so please don't expect it to just work. It is merely a suggestion of an approach that may make your work easier.
      Vector tableData = new Vector();
      ArrayList newValues;
      ViewModel ()
        // in the constructor create an ArrayList for each row that will be displayed
        // and put them in the tableData Vector
        int count = newViewFrame.sortCombo.getItemCount(); // Count is the number of rows?
        for(int i=0;i<count;i++)
          newValues = new ArrayList();
          for (int j = 0; j < numColumns; j++)
            newValues.add();
          tableData.add (newValues);
      // These methods are used by the table and should be supplied
      public int getRowCount ()
      { return tableData.size(); }
      public int getColumnCount ()
      { return 5; }   // the number of columns in your table - this number is used a lot
                      // do not make it complicated to compute
      public void setValueAt(Object value,int row, int col)
        //super.setValueAt(value,row,col); - No point, this is an empty method
        // if the index is out of bounds or nothing was changed return
        if (row < 0 || row >= getRowCount())
          return;
        if (o == null)
        { return; }
        // get the data array for the row which was changed 
        newValues = (ArrayList)tableData.elementAt (row);
        // it doesn't look like your are doing anything for columns 1 -4 ?
        if (column == 0)
          return;
        if (column == 1) 
          return
        else if (column == 2)  
          return;
        else if (column == 3)   
          return;
        else if (column == 4) 
          // not first - do this after you have changed the array
          // fireTableChanged(new TableModelEvent(this,0,4,4));
          Integer colValues[] = TableComboBoxEditor.getColumnValues(((ViewModel)newViewFrame.viewTable.getModel()).getDataVector(),col);
          int retrunValue = alreadyExists(colValues , value);
          System.out.println("the value of row is "+retrunValue);
          if( retrunValue != Integer.MIN_VALUE && retrunValue != row)
            System.out.println("heyheyeheyeheye");
            Set setOfRows = TableComboBoxEditor.hash.keySet();
            Iterator iterator = setOfRows.iterator();
            setValueAtCalled=true;
            int count = newViewFrame.sortCombo.getItemCount();
            // newValues = new ArrayList(); use the one from the dataVector
            for(int i=0;i<count;i++)
              newValues.add(newViewFrame.sortCombo.getItemAt(i));
            // while(iterator.hasNext()){
            // setValueAt(new Integer(0),((Integer)iterator.next()).intValue(),col);
            validatingRemainingColumns(iterator,value,row);
            setValueAtCalled = false;
          // now refresh the table
          fireTableChanged(new TableModelEvent(this,0,4,4));
      // this method creates Integers to set the values in the table
      // If you want Strings instead change it
      public Object getValueAt (int row, int column)
        if (row < 0 || row >= getRowCount())
          return " ";
        newValues = (ArrayList) tableData.elementAt (row);
        if (column == 0)         // set number
          return new Integer (newValues.get(0));
        else if (column == 1)   
          return new Integer (newValues.get(1));
        else if (column == 2)  
          return new Integer (newValues.get(2));
        else if (column == 3)  
          return new Integer (newValues.get(3)));
        else if (column == 4)  
          return new Integer (newValues.get(4)));
        else if (column == 5)  
          return new Integer (newValues.get(5)));
      {\code]

  • [Feature request] Runtime width of JTable columns based on attribute settings

    I'm wondering if it's possible to let 'JClient' dynamically resize the columns in a JTable. Eg: I have set the width of some attribute of some ViewObject to 3. But when I run the application all columns are equally sized. I tried changing the JTable's property autoResizeMode (figuring it might override settings by JClient), but that doesn't seem to have any effect.
    Also, 'grabbing' a column from the table through some manual coding and setting the width of that column doesn't seem to work either.
    I've posted something regarding JTable Re: for specifically RIZWAN from PAkistan or anyone, but I'm curious to know if this 'Specialised editor for Grid Control (JTable)' that Grant Ronald spoke of, will include some sort of applicable functionality.
    It's clear that we need some better (that is, 'any' ;)) way of manipulating columns in a JClient table.
    Any comments?
    Thanks.
    Arno

    We are currently looking into that.
    The column width should not be controlled from the model, it is a setting on JTable, We are considering providing a JClient control (JUTable ??), which is a JTable in a scrollpane and give you more power over column width, column headers etc....
    We are currently evaluating that.
    It would mean that you've got a table control with properties allowing you to set these things on the control itself.
    Currently you have to set the hints on the TableColumn.
    Here is an example :
    tableDeptView1.setModel(JUTableBinding.createAttributeListBinding(panelBinding, tableDeptView1, "DeptView1", null, "DeptView1Iter", new String[] {"Deptno", "Dname", "Loc"}));
    tableDeptView1.getColumn("Deptno").setMaxWidth(75);
    tableDeptView1.getColumn("Loc").setPreferredWidth(200);
    tableDeptView1.getColumn("Loc").setMinWidth(100);
    tableDeptView1.getColumn("Loc").setMaxWidth(450);

  • JTable issues

    I'm using JDK 6 and i would be glad to get answers to the following regarding JTable?
    1) I am using setAutoCreateRowSorter(true) to enable sorting of my JTable columns.
    When i have a sorted column which is editable, how can i prevent the column from getting automatically sorted while editing.
    It should only get sorted when the column header is clicked.
    Sort the score 1 column of my sample code and try to edit a cell, u'll get the picture of what i mean.
    2) While editing JTable, when i press tab or enter, i want the selected cell to clear its contents when i type in a value.
    I've tried searching the forum but haven't got a solution. Any forum link that would help is welcome.
    Thanks
    //class create new class
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.TableModel;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableRowSorter;
    public class TableSample extends JFrame implements ActionListener
         private JButton cancel, count;
         private JTextField filterField;
         private JLabel label;
         private JPanel dataPanel, bPanel, filterPanel;
         private JTable dataTable;
         private TableMap map;
         private DefaultTableModel defModel;
         TableRowSorter tableSorter;
         public TableSample()
              super( "Table Sample" );
              setSize( 450, 400 );
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //setup gui
              filterField = new JTextField();
              filterField.addActionListener(this);
              filterPanel = new JPanel(new BorderLayout());
              filterPanel.add( new JLabel( "Filter" ), BorderLayout.WEST );
              filterPanel.add( filterField, BorderLayout.CENTER );
              bPanel = new JPanel();
              cancel = new JButton( "Close" );
              cancel.addActionListener( this );
              bPanel.add( cancel );
              getContentPane().setLayout( new BorderLayout() );
              dataPanel = new JPanel();
              dataPanel.setLayout( new BorderLayout() );
              //create table
              createTable();
              JScrollPane scrollPane = new JScrollPane(dataTable);
              dataPanel.add( scrollPane, BorderLayout.CENTER );
              //dataPanel.add( ftPanel, BorderLayout.SOUTH );
              getContentPane().add( filterPanel, BorderLayout.NORTH );
              getContentPane().add( scrollPane, BorderLayout.CENTER );
              getContentPane().add( bPanel, BorderLayout.SOUTH );
              setVisible( true );
         public void createTable()
              final String[] columnNames = { "Last Name", "First Name", "Score 1", "Score 2" };
              Object dataObject[][] = { {"Ibrahim", "Musa", "78", "87"}, {"Kapoor", "Vijay", "8", "88"},
                                                 {"John", "Smith", "76", "67"}, {"Thaichi", "Vijay", "96", "64"},
                                                                                     {"Ibrahim", "Hama Adama", "86", "68"}};
              defModel = new DefaultTableModel(dataObject, columnNames);
              map = new TableMap(defModel);
              dataTable = new JTable(map);
              dataTable.setAutoCreateRowSorter(true);
              //set 3rd and 4th columns to be editable
              int editableColumns[] = new int[columnNames.length];
              editableColumns[2] = 1;     
              editableColumns[3] = 1;     
              map.setEditableColumns(editableColumns);
              tableSorter = (javax.swing.table.TableRowSorter)(dataTable.getRowSorter());
         public void actionPerformed( ActionEvent e )
              if(e.getSource() == filterField ) //filter
                   String key = filterField.getText();
                   tableSorter.setRowFilter(RowFilter.regexFilter("(?i)" + key));
              else if( e.getSource() == count )
                   label.setText(String.valueOf(tableSorter.getViewRowCount()));
              else
                   System.exit(0);
         public static void main( String args[] )
              new TableSample();
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.TableModelListener;
    import javax.swing.event.TableModelEvent;
    import java.awt.*;
    public class TableMap extends AbstractTableModel
         implements TableModelListener
         protected TableModel model;
         private int[] editableColumns;
         public TableMap() {}
         public TableMap(TableModel model)
              this.model = model;
              model.addTableModelListener(this);
              editableColumns = new int[this.model.getColumnCount()];
         public TableModel getModel()
              return model;
         public void setModel(TableModel model)
              this.model = model;
              model.addTableModelListener(this);
              editableColumns = new int[this.model.getColumnCount()];
         // By default, implement TableModel by forwarding all messages
         // to the model.
         public void setEditableColumns( int[] c )
              editableColumns = c;
         public Object getValueAt(int aRow, int aColumn)
              return model.getValueAt(aRow, aColumn);
         public void setValueAt(Object aValue, int aRow, int aColumn)
              model.setValueAt(aValue, aRow, aColumn);
         //method to determine the default renderer/editor for each cell
         public Class getColumnClass(int c)
              String nn = new String();
              try
                   if( model.getValueAt(0, c) == null )
                        return nn.getClass();
                   else
                        return model.getValueAt(0, c).getClass();
              catch( ArrayIndexOutOfBoundsException aiobe )
                   System.out.println("Exception: " + aiobe.getMessage());
              return nn.getClass();
         public int getRowCount()
              return (model == null) ? 0 : model.getRowCount();
         public int getColumnCount()
              return (model == null) ? 0 : model.getColumnCount();
         public String getColumnName(int aColumn)
              return model.getColumnName(aColumn);
         public void removeRow( int row )
         public boolean isCellEditable(int row, int column)
              int c = editableColumns[column];
              if( c == 0 )
                   return false;
              else
                   return true;
         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
              return new Choice();
         // Implementation of the TableModelListener interface,
         // By default forward all events to all the listeners.
         public void tableChanged(TableModelEvent e)
              fireTableDataChanged();
              //fireTableChanged(e);
         //public void tableChanged()
              //fireTableDataChanged();
    }

    Post to Project Swing next time :)
    TableModel myModel = new MyModel();
    JTable table = new JTable(myModel);
    then implement those 3 methods which AbstractTableModel leaves to user:
    class MyModel extends AbstractTableModel {
    ... implementation here
    Studing the three methods, plus the rest already implemented, is a good exercise for you ;)
    Bye
    Enrico

  • JTable How to align the Text in a Cell to Centre

    Hi Plese Help regarding JTable.
    I want to align the Text in the Table Cell to Centre how to align it. Im using Abstract Data Model TAble an what is the meaning of renderer and its use.. Help me out

    Here are a couple of links you should read for information on tables and renderers:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender
    http://www-106.ibm.com/developerworks/java/library/j-jtable/index.html?dwzone=java
    Here is an example of a simple renderer that will:
    a) center the text
    b) highlight the background when the cell gets focus
    This renderer is only used in two of the columns of the table.
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableRenderer extends JFrame
         public TableRenderer()
              String[] columnNames = {"Date", "String", "Integer1", "Integer2", "Boolean"};
              Object[][] data =
                   {new Date(), "A", new Integer(1), new Integer(5), new Boolean(true)},
                   {new Date(), "B", new Integer(2), new Integer(6), new Boolean(false)},
                   {new Date(), "C", new Integer(3), new Integer(7), new Boolean(true)},
                   {new Date(), "D", new Integer(4), new Integer(8), new Boolean(false)}
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              JTable table = new JTable( model )
                   //  Returning the Class of each column will allow different
                   //  renderers to be used based on Class
                   public Class getColumnClass(int column)
                        return getValueAt(0, column).getClass();
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
              //  Create cell renderer
              TableCellRenderer centerRenderer = new CenterRenderer();
              //  Use renderer on a specific column
              TableColumn column = table.getColumnModel().getColumn(3);
              column.setCellRenderer( centerRenderer );
              //  Use renderer on a specific Class
              table.setDefaultRenderer(String.class, centerRenderer);
         public static void main(String[] args)
              TableRenderer frame = new TableRenderer();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
         **  Center the text and highlight the focused cell
         class CenterRenderer extends DefaultTableCellRenderer
              public CenterRenderer()
                   setHorizontalAlignment( CENTER );
              public Component getTableCellRendererComponent(
                   JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                   super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                   if (hasFocus)
                        setBackground( Color.cyan );
                   else if (isSelected)
                        setBackground( table.getSelectionBackground() );
                   else
                        setBackground( table.getBackground() );
                   return this;

  • Removing row and collumn in JTable

    guys i have problem regarding JTable.. ive tried to search over the forum to find suitable answer but nothing fits in....
    i need to refresh my JTable but i cant....
    i've tried validate(), repaint() but it doesnt seem to work properly.
    this is the portion of my code that generate the JTable
    public void getTable()
              Statement statement;
              ResultSet resultSet;
              try
                   String query = "SELECT * FROM Booking ";               statement = con.createStatement();
                   resultSet = statement.executeQuery(query);
                   displayResultSet(resultSet);
                   statement.close();
              catch(SQLException sqle)
                   sqle.printStackTrace();
         public void displayResultSet(ResultSet rs) throws SQLException
              boolean moreRecords = rs.next();
              if(!moreRecords)
                   JOptionPane.showMessageDialog(this,"Data not found !","Information Message",JOptionPane.INFORMATION_MESSAGE);
                   return;
              Vector columnHeads = new Vector();
              Vector rows = new Vector();
              try
                   ResultSetMetaData rsmd = rs.getMetaData();
                   for(int i = 1; i <= rsmd.getColumnCount(); ++i)
                        columnHeads.addElement(rsmd.getColumnName(i));
                        do
                             rows.addElement(getNextRow(rs,rsmd));
                        }while(rs.next());
                        table = new JTable(rows, columnHeads);
                        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                        table.setFont(new Font("Arial",Font.BOLD,10));
                        JScrollPane scroller = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                        gbConstraints.fill=GridBagConstraints.BOTH;
                        addComponent(scroller,4,1,4,4); // i use gridbaglayout
              catch(SQLException sqle){
                   sqle.printStackTrace();
         public Vector getNextRow(ResultSet rs, ResultSetMetaData rsmd) throws SQLException
              Vector currentRow = new Vector();
              for(int i = 1; i <= rsmd.getColumnCount(); ++i)
              switch(rsmd.getColumnType(i))
                   case Types.VARCHAR:
                        currentRow.addElement(rs.getString(i));
                        break;
                   case Types.INTEGER:
                        currentRow.addElement(new Long(rs.getLong(i)));
                        break;
                   default:
                        System.out.println("Type was: "+rsmd.getColumnTypeName(i));
              return currentRow;
    when i pressed a button this method will execute again but will show the new updated query if it the database have allready been updated. i tried to validate and repaint but it doesnt work...
    can some one out there tell me how to perform such task ?

    ive tried to search over the forum to find suitable answerJTable is a Swing component and there is a forum for Swing questions. Maybe if you searched the Swing forum (and posted your question there) you would have had better results.
    Here's an [url http://forum.java.sun.com/thread.jsp?forum=57&thread=504709]example (from the Swing forum) that shows how to repopulate a JTable by resetting the DataModel of the table with new data.

  • Refreshing JTable (JDBC)

    Hi there!
    I would like to ask your help regarding JTable.
    I am just new in Java comming from VB. I really cannot understand how JTable works.. since in VB it is very easy to refresh the table/grid.
    Any one who got a simple program (Even using MS Access) that will display DB Table's content to a JTable object and will be able to refresh JTable's content everytime a record is updated? (Even the refreshing of table side only).
    Hope you guys can help me with this since its been weeks already looking for a sample and explanation which is easy to understand.
    Thanks!

    have you tried sun's tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html ?
    JTable is implemented with a data model (table model) as its data container.
    So you need to update the table model first before re-displaying your table. :)

  • JTable editCellAt

    Hello Javaers,
    I've a question for you regarding JTable edits - hoping to save some google time.
    I've a JTable that currently accepts edits by careful overriding of the standard methods, isCellEditable, and by specifying
    ((DefaultCellEditor)table.getDefaultEditor(String.class)).setClickCountToStart(2);     I'd like to disable click-edits at this point, and move the edit function to a context menu. How do I disable click editing?
    Thanks!

    Hey Camickr,
    thanks for checking in as always. I actually discovered what was going on, it had me just as confused as you might have been by my post. I was firing the editCellAt from a JPopupMenu (as a context-menu action). I was puzzled when I saw that the edit wasn't occurring.
    Turns out that it was indeed occurring, just that the disposal of the context menu probably momentarily stole focus from the edit, which was canceling the edit itself. I had to explicitly call dispose before initiating the action, and this solved my problem.
    Thanks - I'll mark it as solved so that you can get some points.
    Cheers!
    Alex

  • Updating multiple records

    Hi,
    Im having issues with updating multiple records.
    This query selects users in a specific unit that are inactive (ui.nf_statusid = 2) and compare it newsmail_recipient table
    select *
                        from roleuser ru, unit u, userinfo ui
                        where u.ip_unitid = ru.nf_unitid
                        and u.ip_unitid = unit_id
                        and ui.ip_userid = ru.nf_userid
                        and ui.nf_statusid = 2
                        and n_internal = 0
                        and ui.ip_userid  in (select user_id
                                                   from newsmail_recipient
                                                  where user_id = ui.ip_userid
                                                    and nf_listid = liste
                                                    and nf_statusid = 1;the second script will set the users to inactive in newsmail_recipient that are inactive in the userinfo table.
    update newsmail_recipient
                 set nf_statusid = 2
                  , d_modified = sysdate
                 where user_id = ui.ip_userid;I would like to know if its possible to merge this query. I know its possible for insert but havent tried update before.
    This is how i do it, but its not working.
    case when (select *
                        from roleuser ru, unit u, userinfo ui
                        where u.ip_unitid = ru.nf_unitid
                        and u.ip_unitid = unit_id
                        and ui.ip_userid = ru.nf_userid
                        and ui.nf_statusid = 2
                        and n_internal = 0
                        and ui.ip_userid  in (select user_id
                                                   from newsmail_recipient
                                                  where user_id = ui.ip_userid
                                                    and nf_listid = liste
                                                    and nf_statusid = 1)
            then update newsmail_recipient
                 set nf_statusid = 2
                  , d_modified = sysdate
                 where user_id = ui.ip_userid;
            end;thanks guys...
    regards,
    j

    Table structure:
    newsmail_recipient:
    IP_RECIPIENTID     NUMBER(8,0)
    NF_LISTID             NUMBER(8,0)
    NF_STATUSID     NUMBER(8,0)
    D_CREATED     DATE
    D_MODIFIED     DATE
    C_NAME             VARCHAR2(100 CHAR)
    C_EMAIL             VARCHAR2(256 CHAR)
    USER_ID             NUMBER(10,0)
    NEWSMAIL_ID     NUMBER(10,0)userinfo:
    IP_USERID             NUMBER(10,0)
    NF_STATUSID     NUMBER(10,0)
    N_INTERNAL     NUMBER(1,0)@jeenesh:
    I tried your query but i get this error:
    Error(510,30): PL/SQL: ORA-00904: "UI"."IP_USERID": invalid identifierJust wondering why, but ui.ip_userid is declared.
    Actually, this is a package script.
    procedure edit_recipient_to_newsmaillist(unit_id IN NUMBER)
            as
            liste number;
            --Finner alle toppfoldere til de lukkede brukergruppene som uniten har tilgang til
            cursor closed_user_group is
              select element_id
               from admin_unit_content_access
              where group_id = 97
                and accesstype_classification_id in( select classification_id
                                                      from dynamic_field_value
                                                      where key = 'closed_user_group'
                                                       and dynamic_field_grouping_id = (select dynamic_field_grouping_id
                                                                                          from unit
                                                                                         where ip_unitid = unit_id))
              and element_type = 'f'; 
          begin
            --Finner hvilken liste folderen tilh�rer
           for u in closed_user_group loop
              if (u.element_id = 39464) then
              liste := 2017; --AMG
              elsif (u.element_id = 36664) then
              liste := 2018; --Das wird meiner
              elsif (u.element_id = 34011) then
              liste := 2019; --Junge sterne   
              elsif (u.element_id = 68359) then
              liste := 2020; --Service vorteilskarte 
              elsif (u.element_id = 1030675) then
              liste := 2021; --TGC
              elsif (u.element_id = 41741) then
              liste := 2022; --Truckworks
              elsif (u.element_id = 118659) then
              liste := 2481; --CRM
              elsif (u.element_id = 122982) then
              liste := 2479; --Vitoecell
              else
              liste := 2037; --Sneak Drive
              end if;
            --oppdater til brukerene i den uniten i listen
               merge into newsmail_recipient nm
                using
                 (select *
                  from roleuser ru, unit u, userinfo ui
                  where u.ip_unitid = ru.nf_unitid
                  and u.ip_unitid = unit_id
                  and ui.ip_userid = ru.nf_userid
                  and ui.nf_statusid = 2
                  and n_internal = 0)
                on (nm.user_id = ui.ip_userid)
                when matched then
                   update set nm.nf_statusid = 2,
                              nm.d_modified = sysdate; 
          liste := 0;
          end loop;
        end edit_recipient_to_newsmaillist;
       

Maybe you are looking for

  • Using Unix Env variables in your Bursting XML

    Hello all, We are going into production bursting invoices using EBS 5.6.2/5.6.3 (we will be upgrading soon) and have come into a issue to do with pathing the files so that we can migrate from dev to prod without altering the XML bursting control file

  • No sound when I connect my p305 to tv

    I connected my p305-s8825 up to my sony rptv. Had no problem getting the picture up on it but for some reason no sound. I was hearing something at first but that was just from the speakers from the laptop. Then I was like wait I need to switch to hdm

  • Iphone 3G MMS not sending

    Hello. Just the other day I finally updated my iphone 3G so I could send MMS/ Picture messages but it doesnt seem to be working. Whenever I try to send an mms it starts to send (the sending bar comes up) but it can never fully send the message and th

  • Accounting document created but the reference billing doc does not exist

    Hi All, We run a custom to program that generate a list accounting docs for clearing. Now our problem is that the reference billing doc of the accounting docs does not exist. It wasn't also archived. The accountings docs are very recent so it is real

  • Read XLS data

    I don't want to be one of those guys that ask questions that have been answered dozens of times (especially about excel) but I have a quick question. The end goal is open an xls file, do some stuff, then save as csv. Pretty simple, and most of the co