JTable RowSelection Problem

Hello,
I have a JTable with the ListSeletionModel as MULTIPLE_INTERVAL_SELECTION. My requirement includes the use of Date-Chooser frame with which I can select a date and set the date related fields in the JTable.(foreg:validfrom and validto).This date-choosing part is working fine,but my probelm is with the row selection.
The situation should be :
- Select a Row
- If the column name is Validfrom or Validto,date-chooser pops up and date can be choosen.
- set the date to the related cells after choosing in the JTable using setValueAt method...
But, my problem is when I first Select a Row and click on the cells related to ValidFrom or ValidTo,the Date-chooser doesnt popup,instead when I first Select the cells whose columnname is either Validfrom or Validto,the date-chooser pops and I can set the dates and this row is now the selected row,
But I want to first select a row and then select the column as validfrom or validto and let the date-chooser pop up and then set the date to these fields for the row selected initially.
Here is the code:
        int cols = table.getColumnModel().getColumnCount();
        cells = new JTextField(20);      
        for (int i = 0; i < cols; i++) {
            TableColumn col = table.getColumnModel().getColumn(i);
            col.setCellEditor(new DefaultCellEditor(cells));
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public Date date;
            public Date present;
            boolean test = true;
            String key = null;
            public void valueChanged(ListSelectionEvent e) { 
                int selectedRow = table.convertRowIndexToModel(table.getSelectedRow());
                int selectedColumn = table.convertColumnIndexToModel(table.getSelectedColumn());
                int columns = table.getColumnModel().getColumnCount();
                key = (String)table.getColumnModel().getColumn(selectedColumn).getHeaderValue();             
                if (key.equalsIgnoreCase("ValidFrom") || (key.equalsIgnoreCase("ValidTo"))) {
                    String tmpDate = (String) table.getModel().getValueAt(selectedRow, selectedColumn);
                    if (tmpDate == null) {
                        Date today = new Date();
                        DATE_FORMAT.format(today);
                        this.date = today;
                        DATE_CHOOSER.setLocationRelativeTo(cells);
                        Date newDate = DATE_CHOOSER.select(this.date);
                        if (newDate == null) {
                            return;
                        cells.setText(DATE_FORMAT.format(newDate));
                        table.getModel().setValueAt(cells.getText(), selectedRow, selectedColumn);
                        table.columnSelectionChanged(e);
                    } else {
                        Date currentDate = UfisTime.getTimeStamp(tmpDate);
                        this.present = currentDate;
                        //   DATE_FORMAT.format(currentDate);
                        DATE_CHOOSER.setLocationRelativeTo(cells);
                        Date newDate = DATE_CHOOSER.select(this.present);
                        if (newDate == null) {
                            return;
                        cells.setText(DATE_FORMAT.format(newDate));
                        table.getModel().setValueAt(cells.getText(), selectedRow, selectedColumn);
                        table.columnSelectionChanged(e);
        });

Thanks!
Do you know of any way to get around it. I've tried requestFocus() without success. Did your answer mean that there is a problem with this method too?
Magnus

Similar Messages

  • JTable size problems due to layout/grid...how can I fix?

    This is my code. When the button "Modify Entries" is pressed, it shows a JTable that imports a file called, "entries.data". The items in this file can be read and saved using this program. The problem is that the table is so small when it first opens. How can I set all my buttons to the very bottom of the form and make the table take up more space at the top? It looks to me as if this layout is treating it with the same dimensions as the buttons'.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    import java.util.*;
    import java.io.*;
    public class CPT extends JPanel implements ActionListener
        protected JButton ModifyEntriesButton, ViewEntriesButton, SearchEntriesButton, SaveButton, BackButton;
        private final static String newline = "\n";
        private DefaultTableModel model;
        public CPT ()
            super (new GridLayout (10, 0));
            model = new PropertiesModel ("entries.data");
            ModifyEntriesButton = new JButton ("Modify Entries");
            ModifyEntriesButton.setVerticalTextPosition (AbstractButton.TOP);
            ModifyEntriesButton.setHorizontalTextPosition (AbstractButton.LEFT);
            ModifyEntriesButton.setToolTipText ("Click this button to modify database entries.");
            ModifyEntriesButton.setMnemonic (KeyEvent.VK_M);
            ModifyEntriesButton.setActionCommand ("ModifyEntries");
            ModifyEntriesButton.addActionListener (this);
            ViewEntriesButton = new JButton ("View Entries");
            ViewEntriesButton.setVerticalTextPosition (AbstractButton.CENTER);
            ViewEntriesButton.setHorizontalTextPosition (AbstractButton.LEFT);
            ViewEntriesButton.setToolTipText ("Click this button to add view all database entries.");
            ViewEntriesButton.setMnemonic (KeyEvent.VK_V);
            ViewEntriesButton.setActionCommand ("ViewEntries");
            ViewEntriesButton.addActionListener (this);
            SearchEntriesButton = new JButton ("Search Entries");
            SearchEntriesButton.setVerticalTextPosition (AbstractButton.BOTTOM);
            SearchEntriesButton.setHorizontalTextPosition (AbstractButton.LEFT);
            SearchEntriesButton.setToolTipText ("Click this button to search through all database entries.");
            SearchEntriesButton.setMnemonic (KeyEvent.VK_S);
            SearchEntriesButton.setActionCommand ("SearchEntries");
            SearchEntriesButton.addActionListener (this);
            SaveButton = new JButton ("Save");
            SaveButton.setVerticalTextPosition (AbstractButton.TOP);
            SaveButton.setHorizontalTextPosition (AbstractButton.RIGHT);
            SaveButton.setToolTipText ("Click this button to save database entries.");
            SaveButton.setMnemonic (KeyEvent.VK_S);
            SaveButton.setActionCommand ("Save");
            SaveButton.addActionListener (this);
            BackButton = new JButton ("Back");
            BackButton.setVerticalTextPosition (AbstractButton.BOTTOM);
            BackButton.setHorizontalTextPosition (AbstractButton.RIGHT);
            BackButton.setToolTipText ("Click this button to return to the main menu.");
            BackButton.setMnemonic (KeyEvent.VK_B);
            BackButton.setActionCommand ("Back");
            BackButton.addActionListener (this);
            add (ModifyEntriesButton);
            add (ViewEntriesButton);
            add (SearchEntriesButton);
        class PropertiesModel extends DefaultTableModel
            public PropertiesModel (String filename)
                addColumn ("Item Number");
                addColumn ("Description");
                addColumn ("Price");
                //Fill model with data from property file
                Properties props = readFile (filename);
                if (props != null)
                    Enumeration coll = props.keys ();
                    while (coll.hasMoreElements ())
                        String property = (String) coll.nextElement ();
                        String value = props.getProperty (property, "");
                        addRow (new Object[]
                            property, value
        private Properties readFile (String filename)
            try
                Properties props = new Properties ();
                props.load (new FileInputStream (filename));
                return props;
            catch (IOException ioe)
                return null;
        private boolean saveFile (String filename)
            try
                Properties props = new Properties ();
                for (int i = 0 ; i < model.getRowCount () ; i++)
                    props.put (model.getValueAt (i, 0), model.getValueAt (i, 1));
                props.store (new FileOutputStream (filename), null);
                return true;
            catch (IOException ioe)
                return false;
        public void actionPerformed (ActionEvent e)
            if ("ModifyEntries".equals (e.getActionCommand ()))
                removeAll ();
                add (new JScrollPane (new JTable (model)), BorderLayout.CENTER);
                add (SaveButton);
                add (BackButton);
                invalidate ();
                updateUI ();
            if ("ViewEntries".equals (e.getActionCommand ()))
                removeAll ();
                add (BackButton);
                invalidate ();
                updateUI ();
            if ("SearchEntries".equals (e.getActionCommand ()))
                removeAll ();
                add (BackButton);
                invalidate ();
                updateUI ();
            if ("Back".equals (e.getActionCommand ()))
                removeAll ();
                add (ModifyEntriesButton);
                add (ViewEntriesButton);
                add (SearchEntriesButton);
                invalidate ();
                updateUI ();
            if ("Save".equals (e.getActionCommand ()))
                if (saveFile ("entries.data"))
                    JOptionPane.showMessageDialog (null, "File saved successfully.");
                else
                    JOptionPane.showMessageDialog (null, "File could not be saved!");
        // Create the GUI and show it. For thread safety,
        // this method should be invoked from the
        // event-dispatching thread.
        private static void createAndShowGUI ()
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated (true);
            //Create and set up the window.
            JFrame frame = new JFrame ("Swisha Computer House");
            frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            JComponent newContentPane = new CPT ();
            newContentPane.setOpaque (true); //content panes must be opaque
            frame.setContentPane (newContentPane);
            //Display the window.
            frame.pack ();
            frame.setSize (300, 300);
            frame.setVisible (true);
        public static void main (String[] args)
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater (new Runnable ()
                public void run ()
                    createAndShowGUI ();
    }Hey, and if anyone knows how to get the first column's numbers from the file to show up in descending order (1 through to, say, 500), please let me know.
    Thank you for any help.

    It looks to me as if this layout is treating it with the same dimensions as the buttons'.Thats the way a GridLayout works.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers. You can mix an match individual Layout Managers to get the effect desired.
    I would suggest you need to change your design. Your code for continually removing and adding components is not the best design. You should probably have a panel with all your buttons. Then you would have different panels for each of your sub functions. The display of these panels would be controlled by a Card Layout. The tutorial has working examples of this.
    You can't use a Properties file to save data from the table (at least not the way you are attempting to use it). I gave you a solution in your last posting.

  • 1.2 / 1.3 JTable getHeaderRenderer() problem

    Hi,
    I've got a Swing Applet which is currently running on 1.2 which I'd now like to upgrade to 1.3 in order to take advantage of the new functionality.
    I've done some preliminary testing, and am encountering problems with the upgrades made to the JTable (see http://java.sun.com/j2se/1.3/docs/guide/swing/JTableChanges.html) in 1.3
    My code uses column.getHeaderRenderer().getTableCellRendererComponent() to get the Header renderer. Unfortunately, the 1.3 implementation has changed so that this now returns null. 1.3 uses table.getTableHeader().getDefaultRenderer() instead.... but this bit of the API doesn't exist in 1.2
    So, please can someone suggest how I might get the code to work for both 1.2 & 1.3 simultaneously?
    Cheers
    RT

    One of the quickest ways around would be to set the header renderer for each column:
    TableCellRenderer headerRenderer = new DefaultTableCellRenderer();
    for(...)
      column.setHeaderRenderer(headerRenderer);
    }That way the column's own renderer would always be used in preference to the default one for a JTableHeader. You might need to play around with the look of it, though.
    The more complete solution would be to use reflection to determine whether the "1.3" method exists and call it if is does. It would be a nasty way to do things, though, and be a maintenance issue in the future.
    try
      Class headerClass = tableHeader.getClass();
      Method method = headerClass.getDeclaredMethod("getDefaultRenderer", new Class[] {});
      headerRenderer = method.invoke(tableHeader, new Object[] {});
    catch(NoSuchMethodException e)
      headerRenderer = column.getHeaderRenderer();
    }Hope this helps.

  • JTable sorting - problem when adding elements (complete code inside)

    I�m writing this email with reference to a recent posting here but this time with the code example. (I apologize for the duplicated posting � this time it will be with the code)
    Problem: when adding more elements to the JTable (sorted) the exception: ArrayIndexOutOfBoundsException is thrown.
    Example: If the elements in the table are 10 and then the user requests for 8 � the table will produce the correct result. However, if the user will ask for 11 items (>10) the exception will be thrown.
    The program: The program below (compiles and running). A JTable is constructed with 3 items, when you click the button - the return result should be 4 items - this will generate the error, WHY?
    I would highly appreciate your thoughts why this is happening and most importantly � how to fix it.
    Thanks a lot
    3 files:
    (1) TableSorterDemo
    (2) Traveler
    (3)TableSorter
    //TableSorterDemo:
    package sorter;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    * TableSorterDemo is like TableDemo, except that it
    * inserts a custom model -- a sorter -- between the table
    * and its data model.  It also has column tool tips.
    public class TableSorterDemo implements ActionListener
         private JPanel superPanel;
         private JButton clickMe = new JButton("click me to get diff data");
         private boolean DEBUG = false;
         private DefaultListModel defaultListModel;
         private JTable table;
        public TableSorterDemo()
             superPanel = new JPanel(new BorderLayout());
             defaultListModel = new DefaultListModel();
             init1();
            TableSorter sorter = new TableSorter(new MyTableModel(defaultListModel)); //ADDED THIS     
            table = new JTable(sorter);             //NEW
            sorter.setTableHeader(table.getTableHeader()); //ADDED THIS
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            //Set up tool tips for column headers.
            table.getTableHeader().setToolTipText(
                    "Click to specify sorting; Control-Click to specify secondary sorting");
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            superPanel.add("Center", scrollPane);
            superPanel.add("South",clickMe);
            clickMe.addActionListener(this);              
        public JPanel getPanel()
             return superPanel;
        public void init1()
             //in real life this will be done from the db
             Traveler a = new Traveler();
             Traveler b = new Traveler();
             Traveler c = new Traveler();
             a.setFirstName("Elvis");
             a.setLastName("Presley");
             a.setSprot("Ping Pong");
             a.setNumYears(3);
             a.setVegetarian(true);
             b.setFirstName("Elton");
             b.setLastName("John");
             b.setSprot("Soccer");
             b.setNumYears(2);
             b.setVegetarian(true);
             c.setFirstName("shaquille");
             c.setLastName("oneil");
             c.setSprot("Golf");
             c.setNumYears(22);
             c.setVegetarian(true);
             defaultListModel.addElement(a);
             defaultListModel.addElement(b);
             defaultListModel.addElement(c);
        public void init2()
             //in real life this will be done from the db
             Traveler d = new Traveler();
             Traveler e = new Traveler();
             Traveler f = new Traveler();
             Traveler g = new Traveler();
             d.setFirstName("John");
             d.setLastName("Smith");
             d.setSprot("Tennis");
             d.setNumYears(32);
             d.setVegetarian(true);
             e.setFirstName("Ron");
             e.setLastName("Cohen");
             e.setSprot("Baseball");
             e.setNumYears(12);
             e.setVegetarian(true);
             f.setFirstName("Donald");
             f.setLastName("Mac Novice");
             f.setSprot("Vallyball");
             f.setNumYears(1);
             f.setVegetarian(true);
             g.setFirstName("Eithan");
             g.setLastName("Superstar");
             g.setSprot("Vallyball");
             g.setNumYears(21);
             g.setVegetarian(true);
             defaultListModel.addElement(d);
             defaultListModel.addElement(e);
             defaultListModel.addElement(f);
             defaultListModel.addElement(g);            
        class MyTableModel extends AbstractTableModel
             private DefaultListModel myModel;
             public MyTableModel(DefaultListModel m)
                  myModel=m;
            private String[] columnNames = {"First Name",
                                            "Last Name",
                                            "Sport",
                                            "# of Years",
                                            "Vegetarian"};
            public int getColumnCount()
                return columnNames.length;
            public int getRowCount()
                return myModel.size();
            public String getColumnName(int column)
                 return getNames()[column];             
             public String[] getNames()
                  String[] names = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
                  return names;
            public Object getValueAt(int row, int col)
                 return distributeObjectsInTable(row, col, (Traveler) myModel.elementAt(row));
            public Object distributeObjectsInTable(int row, int col, Traveler tr)
               switch(col)
                         case 0:
                              return tr.getFirstName();
                         case 1:
                           return tr.getLastName();
                      case 2:
                           return tr.getSprot();
                      case 3:
                           return new Integer(tr.getNumYears());
                      case 4:
                           return new Boolean (tr.isVegetarian());
                     default:
                         return "Error";
            public Class getColumnClass(int c)
                return getValueAt(0, c).getClass();
        private static void createAndShowGUI()
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            JFrame frame = new JFrame("TableSorterDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            TableSorterDemo newContentPane = new TableSorterDemo();
            newContentPane.getPanel().setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane.getPanel());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args)
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable()                   
                public void run()
                    createAndShowGUI();
         public void actionPerformed(ActionEvent ae)
              if (ae.getSource()==clickMe)
                   defaultListModel.removeAllElements();
                   init2(); //if the size of the model was less than 2 items - the result will be ok.
                              //in other words, if you commens the last 2 rows of this method (addElement(f) & g)
                             // the result will be fine.
                   table.updateUI();          
    }//(2) Traveler
    package sorter;
    public class Traveler
         private String firstName;
         private String lastName;
         private String sprot;
         private int numYears;
         private boolean vegetarian;
         public String getFirstName()
              return firstName;
         public String getLastName()
              return lastName;
         public int getNumYears()
              return numYears;
         public String getSprot()
              return sprot;
         public boolean isVegetarian()
              return vegetarian;
         public void setFirstName(String firstName)
              this.firstName = firstName;
         public void setLastName(String lastName)
              this.lastName = lastName;
         public void setNumYears(int numYears)
              this.numYears = numYears;
         public void setSprot(String sprot)
              this.sprot = sprot;
         public void setVegetarian(boolean vegetarian)
              this.vegetarian = vegetarian;
    }//(3)TableSorter
    package sorter;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.*;
    public class TableSorter extends AbstractTableModel {
        protected TableModel tableModel;
        public static final int DESCENDING = -1;
        public static final int NOT_SORTED = 0;
        public static final int ASCENDING = 1;
        private static Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED);
        public static final Comparator COMPARABLE_COMAPRATOR = new Comparator() {
            public int compare(Object o1, Object o2) {
                return ((Comparable) o1).compareTo(o2);
        public static final Comparator LEXICAL_COMPARATOR = new Comparator() {
            public int compare(Object o1, Object o2) {
                return o1.toString().compareTo(o2.toString());
        private Row[] viewToModel;
        private int[] modelToView;
        private JTableHeader tableHeader;
        private MouseListener mouseListener;
        private TableModelListener tableModelListener;
        private Map columnComparators = new HashMap();
        private List sortingColumns = new ArrayList();
        public TableSorter() {
            this.mouseListener = new MouseHandler();
            this.tableModelListener = new TableModelHandler();
        public TableSorter(TableModel tableModel) {
            this();
            setTableModel(tableModel);
        public TableSorter(TableModel tableModel, JTableHeader tableHeader) {
            this();
            setTableHeader(tableHeader);
            setTableModel(tableModel);
        private void clearSortingState() {
            viewToModel = null;
            modelToView = null;
        public TableModel getTableModel() {
            return tableModel;
        public void setTableModel(TableModel tableModel) {
            if (this.tableModel != null) {
                this.tableModel.removeTableModelListener(tableModelListener);
            this.tableModel = tableModel;
            if (this.tableModel != null) {
                this.tableModel.addTableModelListener(tableModelListener);
            clearSortingState();
            fireTableStructureChanged();
        public JTableHeader getTableHeader() {
            return tableHeader;
        public void setTableHeader(JTableHeader tableHeader) {
            if (this.tableHeader != null) {
                this.tableHeader.removeMouseListener(mouseListener);
                TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
                if (defaultRenderer instanceof SortableHeaderRenderer) {
                    this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
            this.tableHeader = tableHeader;
            if (this.tableHeader != null) {
                this.tableHeader.addMouseListener(mouseListener);
                this.tableHeader.setDefaultRenderer(
                        new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
        public boolean isSorting() {
            return sortingColumns.size() != 0;
        private Directive getDirective(int column) {
            for (int i = 0; i < sortingColumns.size(); i++) {
                Directive directive = (Directive)sortingColumns.get(i);
                if (directive.column == column) {
                    return directive;
            return EMPTY_DIRECTIVE;
        public int getSortingStatus(int column) {
            return getDirective(column).direction;
        private void sortingStatusChanged() {
            clearSortingState();
            fireTableDataChanged();
            if (tableHeader != null) {
                tableHeader.repaint();
        public void setSortingStatus(int column, int status) {
            Directive directive = getDirective(column);
            if (directive != EMPTY_DIRECTIVE) {
                sortingColumns.remove(directive);
            if (status != NOT_SORTED) {
                sortingColumns.add(new Directive(column, status));
            sortingStatusChanged();
        protected Icon getHeaderRendererIcon(int column, int size) {
            Directive directive = getDirective(column);
            if (directive == EMPTY_DIRECTIVE) {
                return null;
            return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive));
        private void cancelSorting() {
            sortingColumns.clear();
            sortingStatusChanged();
        public void setColumnComparator(Class type, Comparator comparator) {
            if (comparator == null) {
                columnComparators.remove(type);
            } else {
                columnComparators.put(type, comparator);
        protected Comparator getComparator(int column) {
            Class columnType = tableModel.getColumnClass(column);
            Comparator comparator = (Comparator) columnComparators.get(columnType);
            if (comparator != null) {
                return comparator;
            if (Comparable.class.isAssignableFrom(columnType)) {
                return COMPARABLE_COMAPRATOR;
            return LEXICAL_COMPARATOR;
        private Row[] getViewToModel() {
            if (viewToModel == null) {
                int tableModelRowCount = tableModel.getRowCount();
                viewToModel = new Row[tableModelRowCount];
                for (int row = 0; row < tableModelRowCount; row++) {
                    viewToModel[row] = new Row(row);
                if (isSorting()) {
                    Arrays.sort(viewToModel);
            return viewToModel;
        public int modelIndex(int viewIndex)
            return getViewToModel()[viewIndex].modelIndex;
        private int[] getModelToView()
            if (modelToView == null) {
                int n = getViewToModel().length;
                modelToView = new int[n];
                for (int i = 0; i < n; i++) {
                    modelToView[modelIndex(i)] = i;
            return modelToView;
        // TableModel interface methods
        public int getRowCount() {
            return (tableModel == null) ? 0 : tableModel.getRowCount();
        public int getColumnCount() {
            return (tableModel == null) ? 0 : tableModel.getColumnCount();
        public String getColumnName(int column) {
            return tableModel.getColumnName(column);
        public Class getColumnClass(int column) {
            return tableModel.getColumnClass(column);
        public boolean isCellEditable(int row, int column) {
            return tableModel.isCellEditable(modelIndex(row), column);
        public Object getValueAt(int row, int column) {
            return tableModel.getValueAt(modelIndex(row), column);
        public void setValueAt(Object aValue, int row, int column) {
            tableModel.setValueAt(aValue, modelIndex(row), column);
        // Helper classes
        private class Row implements Comparable {
            private int modelIndex;
            public Row(int index) {
                this.modelIndex = index;
            public int compareTo(Object o) {
                int row1 = modelIndex;
                int row2 = ((Row) o).modelIndex;
                for (Iterator it = sortingColumns.iterator(); it.hasNext();) {
                    Directive directive = (Directive) it.next();
                    int column = directive.column;
                    Object o1 = tableModel.getValueAt(row1, column);
                    Object o2 = tableModel.getValueAt(row2, column);
                    int comparison = 0;
                    // Define null less than everything, except null.
                    if (o1 == null && o2 == null) {
                        comparison = 0;
                    } else if (o1 == null) {
                        comparison = -1;
                    } else if (o2 == null) {
                        comparison = 1;
                    } else {
                        comparison = getComparator(column).compare(o1, o2);
                    if (comparison != 0) {
                        return directive.direction == DESCENDING ? -comparison : comparison;
                return 0;
        private class TableModelHandler implements TableModelListener {
            public void tableChanged(TableModelEvent e) {
                // If we're not sorting by anything, just pass the event along.            
                if (!isSorting()) {
                    clearSortingState();
                    fireTableChanged(e);
                    return;
                // If the table structure has changed, cancel the sorting; the            
                // sorting columns may have been either moved or deleted from            
                // the model.
                if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
                    cancelSorting();
                    fireTableChanged(e);
                    return;
                // We can map a cell event through to the view without widening            
                // when the following conditions apply:
                // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
                // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
                // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
                // d) a reverse lookup will not trigger a sort (modelToView != null)
                // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
                // The last check, for (modelToView != null) is to see if modelToView
                // is already allocated. If we don't do this check; sorting can become
                // a performance bottleneck for applications where cells 
                // change rapidly in different parts of the table. If cells
                // change alternately in the sorting column and then outside of            
                // it this class can end up re-sorting on alternate cell updates -
                // which can be a performance problem for large tables. The last
                // clause avoids this problem.
                int column = e.getColumn();
                if (e.getFirstRow() == e.getLastRow()
                        && column != TableModelEvent.ALL_COLUMNS
                        && getSortingStatus(column) == NOT_SORTED
                        && modelToView != null) {
                    int viewIndex = getModelToView()[e.getFirstRow()];
                    fireTableChanged(new TableModelEvent(TableSorter.this,
                                                         viewIndex, viewIndex,
                                                         column, e.getType()));
                    return;
                // Something has happened to the data that may have invalidated the row order.
                clearSortingState();
                fireTableDataChanged();
                return;
        private class MouseHandler extends MouseAdapter {
            public void mouseClicked(MouseEvent e) {
                JTableHeader h = (JTableHeader) e.getSource();
                TableColumnModel columnModel = h.getColumnModel();
                int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                int column = columnModel.getColumn(viewColumn).getModelIndex();
                if (column != -1) {
                    int status = getSortingStatus(column);
                    if (!e.isControlDown()) {
                        cancelSorting();
                    // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                    // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                    status = status + (e.isShiftDown() ? -1 : 1);
                    status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
                    setSortingStatus(column, status);
        private static class Arrow implements Icon {
            private boolean descending;
            private int size;
            private int priority;
            public Arrow(boolean descending, int size, int priority) {
                this.descending = descending;
                this.size = size;
                this.priority = priority;
            public void paintIcon(Component c, Graphics g, int x, int y) {
                Color color = c == null ? Color.GRAY : c.getBackground();            
                // In a compound sort, make each succesive triangle 20%
                // smaller than the previous one.
                int dx = (int)(size/2*Math.pow(0.8, priority));
                int dy = descending ? dx : -dx;
                // Align icon (roughly) with font baseline.
                y = y + 5*size/6 + (descending ? -dy : 0);
                int shift = descending ? 1 : -1;
                g.translate(x, y);
                // Right diagonal.
                g.setColor(color.darker());
                g.drawLine(dx / 2, dy, 0, 0);
                g.drawLine(dx / 2, dy + shift, 0, shift);
                // Left diagonal.
                g.setColor(color.brighter());
                g.drawLine(dx / 2, dy, dx, 0);
                g.drawLine(dx / 2, dy + shift, dx, shift);
                // Horizontal line.
                if (descending) {
                    g.setColor(color.darker().darker());
                } else {
                    g.setColor(color.brighter().brighter());
                g.drawLine(dx, 0, 0, 0);
                g.setColor(color);
                g.translate(-x, -y);
            public int getIconWidth() {
                return size;
            public int getIconHeight() {
                return size;
        private class SortableHeaderRenderer implements TableCellRenderer {
            private TableCellRenderer tableCellRenderer;
            public SortableHeaderRenderer(TableCellRenderer tableCellRenderer) {
                this.tableCellRenderer = tableCellRenderer;
            public Component getTableCellRendererComponent(JTable table,
                                                           Object value,
                                                           boolean isSelected,
                                                           boolean hasFocus,
                                                           int row,
                                                           int column) {
                Component c = tableCellRenderer.getTableCellRendererComponent(table,
                        value, isSelected, hasFocus, row, column);
                if (c instanceof JLabel) {
                    JLabel l = (JLabel) c;
                    l.setHorizontalTextPosition(JLabel.LEFT);
                    int modelColumn = table.convertColumnIndexToModel(column);
                    l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
                return c;
        private static class Directive {
            private int column;
            private int direction;
            public Directive(int column, int direction) {
                this.column = column;
                this.direction = direction;
    }

    The table listens to the TableModel for changes. Changing the table by adding/removing
    rows or columns has no affect on its table model. If you make changes to the table model
    the table will be notified by its TableModelListener and change its view. So tell
    MyTableModel about the change of data:
    public class TableSorterDemo implements ActionListener
        MyTableModel tableModel;
        public TableSorterDemo()
            defaultListModel = new DefaultListModel();
            init1();
            tableModel = new MyTableModel(defaultListModel);
            TableSorter sorter = new TableSorter(tableModel);
        public void actionPerformed(ActionEvent ae)
            if (ae.getSource()==clickMe)
                defaultListModel.removeAllElements();
                init2();
                tableModel.fireTableStructureChanged();
    }

  • JTable printing problem

    Hi , I have a problem add printing routine for printing to this code.
    Sombody help me.
    I no post all code but my prube no functioned.
    thanks you
    code :
    package com.froses.tablemodels;
    * SimpleDBTable.java
    * A demonstration of using ODBC to read data from an Access database
    * and display the values in a JTable.
    * This file requires that the new.mdb file exists and has been mapped
    * using ODBC to a datastore named 'newdb' with blank username and password.
    * Gordon Branson January 2004
    import javax.swing.*;
    import java.awt.Dimension;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class SimpleDBTable extends JPanel {
    private boolean DEBUG = true;
    private int rows = 10, cols = 5;
    private String url = "jdbc:odbc:Sego";
    private Connection con;
    private Statement stmt;
    private JButton btnRead, btnDelete, btnWrite, btnClose;
              /* Setup the table column names */
    private String[] columnNames = {"Medico",
    "Descripci�n",
    "Obra social",
    "Items",
    "Codigo"};
              /* declare an Object array large enough to hold the database table */
    private Object[][] data = new Object[rows][cols];
    private JTable table;
    public SimpleDBTable() {
    super(new BorderLayout());
    /* Load ODBC diver */
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(e.getMessage());
              /* create the JTable */
    table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(500, 300));
    /* Now read from the database */
    populateTable();
    if (DEBUG) {
    table.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    printDebugData();
    //Create the Title Label.
    JLabel title = new JLabel("Database Access in Java");
    title.setFont(new java.awt.Font("Arial", 1, 24));
    title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    //Add the label to this panel.
    add("North",title);
    //Create the scroll pane and add the JTable to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this panel.
    add("Center",scrollPane);
    // Create a button panel with a default layout
    JPanel buttons = new JPanel();
    // Create the buttons
    btnRead = new JButton("Read");
    btnClose = new JButton("Close");
    btnWrite = new JButton("Write");
    btnDelete = new JButton("Delete");
    // Add action listeners
    btnRead.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    populateTable();
    btnDelete.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    deleteTable();
    btnWrite.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    writeTable();
    btnClose.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    System.exit(0);
    // Add the buttons to the button panel
    buttons.add(btnRead);
    buttons.add(btnWrite);
    buttons.add(btnDelete);
    buttons.add(btnClose);
    // Add the buttons panel to main panel
    add("South",buttons);
    private void populateTable(){
         /* Define the SQL Query to get all data from the database table */
    String query = "SELECT * FROM Datos";
    /* First clear the JTable */
    clearTable();
    /* get a handle for the JTable */
    javax.swing.table.TableModel model = table.getModel();
    int r = 0;
    try {
    /* connect to the database */
    con = DriverManager.getConnection(url, "", "");
    stmt = con.createStatement();
    /* run the Query getting the results into rs */
                   ResultSet rs = stmt.executeQuery(query);
                   while ((rs.next()) && (r<rows)) {
                        /* for each row get the fields
                        note the use of Object - necessary
                        to put the values into the JTable */
                   Object nm = rs.getObject("Medico_solic");
                   Object sup = rs.getObject("Descip_Item");
                   Object pri = rs.getObject("Obra_Social");
                   Object sal = rs.getObject("M�dico_opera");
                   Object tot = rs.getObject("Codigo_estudio");
                   model.setValueAt(nm, r, 0);
                   model.setValueAt(sup, r, 1);
                   model.setValueAt(pri, r, 2);
                   model.setValueAt(sal, r, 3);
                   model.setValueAt(tot, r, 4);
                   r++;
    stmt.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    private void deleteTable(){
         emptyTable();
         clearTable();
    private void emptyTable(){
         /* Define the SQL Query to get all data from the database table */
    String query = "DELETE * FROM COFFEES";
    try {
    /* connect to the database */
    con = DriverManager.getConnection(url, "", "");
    stmt = con.createStatement();
    /* run the Query */
                   stmt.executeUpdate(query);
    stmt.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    /* private void writeTable(){
         /* First clear the table */
    /*      emptyTable();
         PreparedStatement insertRow;// = con.prepareStatement(
         String insertString = "INSERT INTO COFFEES " +
                                  "VALUES (?, ?, ?, ?, ?)";
    int numRows = table.getRowCount();
    javax.swing.table.TableModel model = table.getModel();
    Integer sup, sal, tot;
    Double pri;
    Object o;
    if(DEBUG) System.out.println("\nDoing Write...");
    try {
    /* connect to the database */
    /* con = DriverManager.getConnection(url, "", "");
    insertRow = con.prepareStatement(insertString);
         for (int r=0; r < numRows; r++) {
              if (model.getValueAt(r, 0) != null){
                   insertRow.setString(1, (String) model.getValueAt(r, 0));
                   //o = model.getValueAt(r, 1);
                   if(DEBUG) System.out.println(model.getValueAt(r, 1).toString());
                   sup = new Integer((String) model.getValueAt(r, 1));
                   insertRow.setInt(2, sup.intValue());
                   pri = new Double((String) model.getValueAt(r, 2));
                   insertRow.setDouble(3, pri.doubleValue());
                   sal = new Integer((String) model.getValueAt(r, 3));
                   insertRow.setInt(4, sal.intValue());
                   tot = new Integer((String) model.getValueAt(r, 4));
                   insertRow.setInt(5, tot.intValue());
                   insertRow.executeUpdate();
                   System.out.println("Writing Row " + r);
    insertRow.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    clearTable();
    private void writeTable(){
         /* First clear the table */
         emptyTable();
         Statement insertRow;// = con.prepareStatement(
         String baseString = "INSERT INTO Datos " +
                                  "VALUES ('";
         String insertString;
    int numRows = table.getRowCount();
    javax.swing.table.TableModel model = table.getModel();
    Integer sup, sal, tot;
    Double pri;
    Object o;
    if(DEBUG) System.out.println("\nDoing Write...");
    try {
    /* connect to the database */
    con = DriverManager.getConnection(url, "", "");
         for (int r=0; r < numRows; r++) {
              if (model.getValueAt(r, 0) != null){
                   insertString = baseString + model.getValueAt(r, 0)+"',";
                   insertString = insertString + model.getValueAt(r, 1)+",";
                   insertString = insertString + model.getValueAt(r, 2)+",";
                   insertString = insertString + model.getValueAt(r, 3)+",";
                   insertString = insertString + model.getValueAt(r, 4)+");";
                   if(DEBUG) System.out.println(insertString);
              insertRow = con.createStatement();
                   insertRow.executeUpdate(insertString);
                   System.out.println("Writing Row " + r);
    insertRow.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    clearTable();
    private void clearTable(){
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    for (int i=0; i < numRows; i++) {
    for (int j=0; j < numCols; j++) {
    model.setValueAt(null, i, j);
    private void printDebugData() {
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    System.out.println("Value of data: ");
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + model.getValueAt(i, j));
    System.out.println();
    System.out.println("--------------------------");
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("SimpleDBTable");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    SimpleDBTable newContentPane = new SimpleDBTable();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }

    http://forum.java.sun.com/thread.jspa?threadID=626207

  • Intermittent JTable Selection Problem

    Hi,
    Everyone once in a while, under NT with 1.4.x, I have problems selecting and highlighting row under JTable. It happens a good bit, but this does not happen all the time. When the table is buggy, it does not keep the row selected nor does it highlight the row. You may have the row selected on a mousedown, but once you release the mouse it's done.
    Since this is happening for a variety of JTable's I didn't bother to send Java code. Has anyone else encountered this sort of thing? Or does anyone know what I should be looking at?
    The intermittent part is what's killing me. It makes it hard to track down with any high degreee of confidence in the answers.
    thanks for any input or suggestions,
    Geoff

    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class Test extends JFrame {
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        String[] head = {"One","Two","Three"};
        String[][] data = new String[40][3];
        for (int r=0; r<40; r++) {
          data[r] = new String[3];
          for (int c = 0; c < 3; c++) data[r][c] = "R" + r + "-C" + c;
        content.add(new JScrollPane(new JTable(data,head)));
        setSize(400, 400);
        show();
      public static void main(String args[]) { new Test(); }
    }I've been clicking until my fingers bled. Can't see a problem.

  • JTable rendering problem in JRE 1.6.0.10 under Linux

    I've encountered a bizarre issue using JTable. I've got a 3x10 JTable of Strings, values in which I change from within the program (no user input). After every update the value in the first column gets superimposed on the top of the previous one, so they are both visible, but totally unreadable (they interlace).
    I'm using Linux, and it only happens under jre 1.6.0.10. When I switch to 1.5.0.16 it works fine. I also noticed, that if I set the value to null in the first column and then set it to the new value it works fine. However, if I do it simply like that:
    table.setValueAt(null, 1, 0);
    table.setValueAt(newValue, 1, 0);it doesn't work. I need to re-set it to null on one user's click (it triggers the update) and only change it on the following click. Am I reporting a bug here, or is it a known issue with some proper solution?
    Thanks

    There are some crazy things, I can't explain...
    1) Here is my [sample project|http://vlkv.storm-soft.kiev.ua/_mywiki/images/6/6f/JavaApplication1.tar.gz]. I've created it with NetBeans 6.5 and jdk 1.6.0_11.
    2) there are directories dist_windows, dist_linux with jars, created under Windows and Linux (same version JDK everywhere). You may compare both JavaApplication1.jar files with some diff tool (such as WinMerge) and you can see that these jars are slightly different. WHY?
    3) Run my sample
    java -jar JavaApplication1.jarpress the button and scroll up and down JTable. Under Windows everything is ok. But under Linux I have the subj bug with BOTH dist_windows/JavaApplication1.jar and dist_linux/JavaApplication1.jar !!!
    4) Start NetBeans 6.5 and open the project. Run the project from inside NetBeans on Linux. Then I see that my java program runs perfectly, without any bugs!!!
    This command
    ps fu -C javaproduces this output:
    vlkv 8778 1.0 2.8 217084 22408 ? Sl 14:01 0:00 \_ /usr/java/jdk1.6.0_11/bin/java -classpath /home/vlkv/NetBeansProjects/JavaApplication1/build/classes:/home/vlkv/NetBeansProjects/JavaApplication1/src NewJFrame
    But if I run NewJFrame without NetBeans like this (copy/paste command):
    /usr/java/jdk1.6.0_11/bin/java -classpath /home/vlkv/NetBeansProjects/JavaApplication1/build/classes:/home/vlkv/NetBeansProjects/JavaApplication1/src NewJFrame
    This bug returns!!! WHY UNDER NETBEANS IT'S OKAY?
    Where are the java experts to help us, please?
    PS: I've found a topic about this problem, unfortunately not answered, here .

  • JTable - getValueAt Problem

    I am new to Java and am having a problem with a JTable. I want the user to enter 12 months of rain that will go into an array list. The input sreen is O.K., but I cant retrieve the data or clear the cells. Any suggestings would be appreciated. Here is the code. Thanks Ronnie
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.BorderFactory.*;
    import javax.swing.table.*;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import javax.swing.JMenuBar;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class GridBagWindow extends JFrame implements ActionListener,
    FocusListener {
    public GridBagWindow() {
    setTitle("User Rainfall Data");
    JComboBox userCboRainCounty, userCboRainYr;
    DefaultTableModel dtmUserRain = new DefaultTableModel();
    JMenuBar userRainJMB = new JMenuBar();
    JMenu userRainfileMenu = new JMenu("File");
    JMenu userRainprintMenu = new JMenu("Print");
    JMenu userRainclearMenu = new JMenu("Clear");
    JMenu userRaintotalsMenu = new JMenu("Totals");
    // Need to add additional menu option because evnet can not be added
    // directly to JMenu
    JMenuItem userRainOpen = new JMenuItem("Open");
    JMenuItem userRainSave = new JMenuItem("Save");
    JMenuItem userRainPrint = new JMenuItem("Print");
    JMenuItem userRainClear = new JMenuItem("Clear");
    JMenuItem userRainTotals = new JMenuItem("Totals");
    userRainJMB.add(userRainfileMenu);
    userRainfileMenu.add(userRainOpen);
    userRainfileMenu.add(userRainSave);
    userRainJMB.add(userRainprintMenu);
    userRainprintMenu.add(userRainPrint);
    userRainJMB.add(userRainclearMenu);
    userRainclearMenu.add(userRainClear);
    userRainJMB.add(userRaintotalsMenu);
    userRaintotalsMenu.add(userRainTotals);
    userRainOpen.addActionListener(this);
    userRainSave.addActionListener(this);
    userRainPrint.addActionListener(this);
    userRainClear.addActionListener(this);
    userRainTotals.addActionListener(this);
    setJMenuBar(userRainJMB);
    Container contentPane = getContentPane();
    setFont(new Font("Arial", Font.BOLD, 16));
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    contentPane.setLayout(gridbag);
    int width = 800;
    int height = 500;
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - width) / 2;
    int y = (screen.height - height) / 2;
    setBounds(x, y, 600, 600);
    setJMenuBar(userRainJMB);
    JLabel userRainLblCounty = new JLabel(
    " County");
    userRainLblCounty.setFont(new Font("Arial", Font.BOLD, 16));
    buidConstraints(c, 2, 0, 1, 1, 0, 0);
    c.anchor = GridBagConstraints.EAST;
    c.insets = new Insets(1, 25, 1, 1);
    gridbag.setConstraints(userRainLblCounty, c);
    contentPane.add(userRainLblCounty);
    userCboRainCounty = new JComboBox();
    userCboRainCounty.setFont(new Font("Arial", Font.BOLD, 16));
    userCboRainCounty.setBackground(Color.white);
    buidConstraints(c, 3, 0, 1, 1, 0, 0);
    c.insets = new Insets(1, 1, 1, 1);
    c.anchor = GridBagConstraints.EAST;
    gridbag.setConstraints(userCboRainCounty, c);
    userCboRainCounty.addFocusListener(this);
    contentPane.add(userCboRainCounty);
    String[] header = { "Jan", "Feb", "Mar", "Apr", "May", "June",
    "July", "Aug", "Sep", "Oct", "Nov", "Dec", "Total" };
    DefaultTableModel dftModel = new DefaultTableModel(header, 1);
    JTable userRainTable = new JTable(dftModel);
    userRainTable.setEnabled(true);
    JScrollPane scrollPane = new JScrollPane(userRainTable);
    buidConstraints(c, 1, 1, 3, 1, 0, 0);
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(10, 10, 1, 1);
    gridbag.setConstraints(scrollPane, c);
    contentPane.add(scrollPane);
    JLabel userRainLblRain = new JLabel("Rain (in)");
    userRainLblCounty.setFont(new Font("Arial", Font.BOLD, 16));
    buidConstraints(c, 0, 1, 1, 1, 0, 0);
    c.anchor = GridBagConstraints.EAST;
    gridbag.setConstraints(userRainLblRain, c);
    contentPane.add(userRainLblRain);
    userRainTable
    .setPreferredScrollableViewportSize(new Dimension(600, 20));
    JLabel userRainLblRainYr = new JLabel("Rainfall Years");
    userRainLblRainYr.setFont(new Font("Arial", Font.BOLD, 16));
    buidConstraints(c, 0, 2, 1, 1, 0, 0);
    c.anchor = GridBagConstraints.SOUTH;
    c.insets = new Insets(0, 1, 1, 1);
    gridbag.setConstraints(userRainLblRainYr, c);
    contentPane.add(userRainLblRainYr);
    userCboRainYr = new JComboBox();
    userCboRainYr.setFont(new Font("Arial", Font.BOLD, 16));
    userCboRainYr.setBackground(Color.white);
    buidConstraints(c, 1, 2, 1, 1, 0, 0);
    c.insets = new Insets(1, 1, 1, 1);
    c.anchor = GridBagConstraints.EAST;
    gridbag.setConstraints(userCboRainYr, c);
    // userCboRainCounty.addFocusListener(this);
    contentPane.add(userCboRainYr);
    JLabel userRainLblTitle = new JLabel("Title");
    userRainLblTitle.setFont(new Font("Arial", Font.BOLD, 16));
    buidConstraints(c, 2, 2, 1, 1, 0, 0);
    c.anchor = GridBagConstraints.EAST;
    // c.insets = new Insets(1, 14,1,1);
    gridbag.setConstraints(userRainLblTitle, c);
    contentPane.add(userRainLblTitle);
    JTextField userRainTxtTitle = new JTextField(18);
    userRainTxtTitle.setFont(new Font("Arial", Font.BOLD, 16));
    buidConstraints(c, 3, 2, 1, 1, 0, 0);
    c.anchor = GridBagConstraints.EAST;
    c.insets = new Insets(1, 1, 1, 1);
    gridbag.setConstraints(userRainTxtTitle, c);
    contentPane.add(userRainTxtTitle);
    JLabel userLblRainBlank = new JLabel(" ");
    buidConstraints(c, 0, 3, 4, 4, 0, 0);
    c.insets = new Insets(15, 15, 1, 1);
    gridbag.setConstraints(userLblRainBlank, c);
    contentPane.add(userLblRainBlank);
    JButton userBtnRainDefault = new JButton(" Default ");
    userBtnRainDefault.setFont(new Font("Arial", Font.BOLD, 16));
    userBtnRainDefault.setBorder(BorderFactory.createRaisedBevelBorder());
    buidConstraints(c, 1, 4, 1, 1, 0, 0);
    c.anchor = GridBagConstraints.EAST;
    gridbag.setConstraints(userBtnRainDefault, c);
    contentPane.add(userBtnRainDefault);
    JButton userBtnRainCancel = new JButton(" Cancel ");
    userBtnRainCancel.setFont(new Font("Arial", Font.BOLD, 16));
    userBtnRainCancel.setBorder(BorderFactory.createRaisedBevelBorder());
    buidConstraints(c, 2, 4, 1, 1, 0, 0);
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(15, 0, 0, 0);
    gridbag.setConstraints(userBtnRainCancel, c);
    contentPane.add(userBtnRainCancel);
    JButton userBtnRainOK = new JButton(" O.K ");
    userBtnRainOK.setFont(new Font("Arial", Font.BOLD, 16));
    userBtnRainOK.setBorder(BorderFactory.createRaisedBevelBorder());
    buidConstraints(c, 3, 4, 1, 1, 20, 20);
    c.insets = new Insets(15, 0, 0, 150);
    c.anchor = GridBagConstraints.EAST;
    gridbag.setConstraints(userBtnRainOK, c);
    userBtnRainOK.addActionListener(this);
    contentPane.add(userBtnRainOK);
    // //User Definded Cold Protection
    // Input Combo Box for County Selection, two counties per line
    userCboRainCounty.addItem("CHARLOTTE");
    userCboRainCounty.addItem("CITRUS");
    userCboRainCounty.setSelectedIndex(5);
    userCboRainYr.addItem(String.valueOf(1));
    userCboRainYr.addItem(String.valueOf(5));
    userCboRainYr.addItem(String.valueOf(10));
    userCboRainYr.setSelectedIndex(-1);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    pack();
    setVisible(true);
    void buidConstraints(GridBagConstraints c, int gx, int gy, int gw, int gh,
    int wx, int wy) {
    c.gridx = gx;
    c.gridy = gy;
    c.gridwidth = gw;
    c.gridheight = gh;
    c.weightx = wx;
    c.weighty = wy;
    public void focusGained(FocusEvent af) {
    // if(af.getSource() == userRainTable){
    // userRainTable.setBackground(Color.yellow);
    public static void main(String args[]) {
    GridBagWindow window = new GridBagWindow();
    public void actionPerformed(ActionEvent evt) {
    String actionName = evt.getActionCommand();
    System.out.println("Button \"" + actionName + "\" was pressed.");
    // userRainTable.getValueAt(1,1);
    if (actionName == "Clear") {
    for (int i = 0; i > 14; i++) {
    // userRainfallTable.setValueAt(0, 1 , 1);
    System.out.println("Yes Continue");
    if (actionName == "Totals") {
    System.out.println("Yes Continue");
    }

    Hello Ronnie,
    this is a nice little piece of code. ;-)
    No chance of reducing it a little bit just to show the problem?
    And what about making it at least to compile error free? (Just tried on 1.5_06)
    Also place tags around to make it more readable.
    Regards
    J�rg                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • JTable select problem

    Hello,
    I have a great problem with my JTable. I have a JTable with few lines and two columns. The user can select one line and with the following statements
    int column = tblSearchResults.getSelectedColumn();
    int row = tblSearchResults.getSelectedRow();     
    Object value = tblSearchResults.getValueAt(row,column);
    I retrieve the value with which I display details of a second line in a new window (when the user presses a certain button). The problem is when I close this new window and want to select a new line the getSelectedColumn and the getSelectedRow returns always -1 which says that no line is marked although I have marked a line.
    Does anybody know what the problem can be? - it must concern the open and close of the detail window, because when I omit the code line which opens the detail window and only make System.out.println's with the getSelectedColumn and getSelectedRow it will always output the right line...
    thx
    pat

    Swing related questions should be posted in the Swing forum.
    You have not provided enough information to solve your problem. We don't know how you are invoking the dialog. Are you double clicking on a row, do you have a button the user clicks on to invoke processing?
    So for this, and future postings, you should learn how to create a simple demo program that shows your problem so we don't have to guess what you are doing.

  • JTable scrolling problem...

    I am having a problem with my JTable scrolling to show the newest added row. I have it working, but it jumps. Here is my problem.
    I have the enter key acting like the tab key. I can force the scroll to the active cell but it jumps to row 0 for just a split second.
    I know the problem is the way that I handle the Enter key. When I press enter I drop a cell down but then I force it back up.
    Does any one know how to fix this? Here is some of the code that I am using...
    if (event.getKeyChar() == '\n')
    int r = tblDetailEntry.getSelectedRow();
    int c = tblDetailEntry.getSelectedColumn();
    if(r == 0)
    r = curBill.billDetail.size();
    c--;
    if(r <= curBill.billDetail.size())
    r--;
    if(c == curBill.CODE)
    c = 0;
    if(r == curBill.billDetail.size() - 1)
    detailEntry.addLine();     
    r = curBill.billDetail.size() - 1;               
    else
    r++;
    Rectangle rect = tblDetailEntry.getCellRect(r, 0, true);
    tblDetailEntry.scrollRectToVisible(rect);
    tblDetailEntry.editCellAt(r,c + 1);
    tblDetailEntry.setRowSelectionInterval(r,r);
    tblDetailEntry.setColumnSelectionInterval(c + 1,c + 1);     
    }

    My app is a bit more complex. It includes search criteria (Textboxes) and a
    submit button which will write a dynamic SQL statment, execute and fill a table > thin an internal scrollpaneIt doesn't matter that you are using a "dynamic SQL statement". Whats important is how you build your TableModel and the TableModel you are using. I gave you an example that will use the DefaultTableModel and will work for a single row or 1,000 rows in the ResultSet.
    Your question didn't state whether you are using the the DefaultTableModel or a custom TableModel. If you are using a custom TableModel, then chances are you have an error in you TableModel.
    In no way am I asking for you or anyone else to supply me with code. Only a
    possible step in the right direction. This is exactly what my example did. It proved to you that it works. So you look at your code and see what the differences are between one that works and one that doesn't. The example has three basic lines of code to build a scrollable table:
    JTable table = new JTable(data, columnNames);
    JScrollPane scrollPane = new JScrollPane( table );
    getContentPane().add( scrollPane );
    I don't know how is can get any simpler than that, so I would have no idea what to suggest you are doing wrong. Are you mixing AWT and Swing components?

  • Strange JTable update problems

    I am having some strange issues with a JTable.
    I have a custom AbstractTableModel that displays various properties of a list of Objects. I am using a java.util.Vector to store this list.
    The user is given several JComboBox objects which contain filters for my table, when any of these filters are changed, a class that manages my Database is asked to return a Vector full of objects that match these filters.
    I then set my table data Vector equal to this returned list and invoke fireTableStructureChanged() from my table model. This part works fine, the strange thing is, if the user has a table element selected and then they change the filters, the table will not update, it actually goes blank, but oddly enough the scroll bar on the scroll pane stays the same length as the old table.
    When I invoke the exact same update method again (which just sets the Vector containing my data to a new value, and fires the event) the table will update this time.
    I have tried calling MyJTable.getSelectionModel().clearSelection() in the hope that it will fix my problem, but it does not seem to do anything.
    So is my problem some strange event or threading glitch, or an issue with JScrollPane mabye?
    Thanks in advance for any help

    Try using the DefaultTableModel to see if you have the same problem. If not then you know the problem is with your custom TableModel.
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",
    see http://homepage1.nifty.com/algafield/sscce.html,
    that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the "Code Formatting Tags",
    see http://forum.java.sun.com/help.jspa?sec=formatting,
    so the posted code retains its original formatting.

  • JTable: renderer problem-urgent

    Thanx "pasteven". That url is too good.
    I wrote my own renderer for each cell in JTable that uses JCombobox for rendering purpose. But when i select an item in that combo box, some times renderer is not setting the selected item in that combobox. Sometimes when i change the selection of item in the previous cell,it is getting reflected in all other cells of that particular column.
    Here is my code. Please help me.
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.table.TableCellEditor.*;
    import javax.swing.table.*;
    import javax.swing.DefaultCellEditor;
    public class Render extends javax.swing.JFrame {
    JTextField textField0=new JTextField();
    JComboBox cmb_Editor1=new JComboBox();
    JComboBox cmb_Editor2=new JComboBox();
    JComboBox cmb_Editor3=new JComboBox();
    EachRowRenderer rend;
    EachRowEditor eee;
    /** Creates new form Render */
    public Render() {
    initComponents ();
    rend=new EachRowRenderer();
    eee=new EachRowEditor(table);
    table.setDefaultRenderer(java.lang.Object.class,rend);
    table.setDefaultEditor(java.lang.Object.class,eee);
    cmb_Editor3.addItem("Y");
    cmb_Editor3.addItem("N");
    eee.setEditorAt(0,1,new DefaultCellEditor(cmb_Editor3));
    eee.setEditorAt(1,1,new DefaultCellEditor(cmb_Editor3));
    eee.setEditorAt(2,1,new DefaultCellEditor(cmb_Editor3));
    eee.setEditorAt(0,2,new DefaultCellEditor(new JCheckBox()));
    rend.add(0,2,new CheckBoxCellRenderer());
    rend.add(0,1,new ComboBoxCellRenderer(cmb_Editor3));
    rend.add(1,1,new ComboBoxCellRenderer(cmb_Editor3));
    rend.add(2,1,new ComboBoxCellRenderer(cmb_Editor3));
    JCheckBox chk=new JCheckBox();
    pack ();
    public class EachRowEditor implements TableCellEditor {
    protected Hashtable editors;
    protected TableCellEditor editor, defaultEditor;
    JTable table;
    public EachRowEditor(JTable table) {
    this.table = table;
    editors = new Hashtable();
    defaultEditor = new DefaultCellEditor(new JTextField());
    public void setEditorAt(int row,int column, TableCellEditor editor) {
    editors.put(""+row+column,editor);
    public Component getTableCellEditorComponent(JTable table,
    Object value, boolean isSelected, int row, int column) {
    return editor.getTableCellEditorComponent(table,
    value, isSelected, row, column);
    public Object getCellEditorValue() {
    return editor.getCellEditorValue();
    public boolean stopCellEditing() {
    return editor.stopCellEditing();
    public void cancelCellEditing() {
    editor.cancelCellEditing();
    public boolean isCellEditable(EventObject anEvent) {
    selectEditor((MouseEvent)anEvent);
    // editor.isCellEditable(anEvent);
         return true;
    public void addSeperateCellEditorListener(int row,int column,CellEditorListener l) {
    editor=(TableCellEditor)editors.get(""+row+column);
    editor.addCellEditorListener(l);
    public void addCellEditorListener(CellEditorListener l) {
    editor.addCellEditorListener(l);
    public void removeCellEditorListener(CellEditorListener l) {
    editor.removeCellEditorListener(l);
    public boolean shouldSelectCell(EventObject anEvent) {
    selectEditor((MouseEvent)anEvent);
    return editor.shouldSelectCell(anEvent);
    protected void selectEditor(MouseEvent e) {
    int row;
    int column;
    if (e == null) {
    row = table.getSelectionModel().getAnchorSelectionIndex();
    column=table.getSelectionModel().getLeadSelectionIndex();
    } else {
    row = table.rowAtPoint(e.getPoint());
    column=table.columnAtPoint(e.getPoint());
    editor = (TableCellEditor)editors.get(""+row+column);
    if (editor == null) {
    editor = defaultEditor;
    public class CheckBoxCellRenderer extends JCheckBox implements TableCellRenderer
    CheckBoxCellRenderer() {
    setHorizontalAlignment(JLabel.CENTER);
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setSelected((value != null && ((Boolean)value).booleanValue()));
    setToolTipText("checkbox");
    return this;
    public class TextFieldCellRenderer extends JTextField implements TableCellRenderer
    JTextField textField;
    TextFieldCellRenderer(JTextField textField) {
    this.textField=textField;
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setText((textField.getText() != null) ? textField.getText() : "");
    return textField;
    public class ComboBoxCellRenderer extends JComboBox implements TableCellRenderer
    JComboBox comboBox=null;
    ComboBoxCellRenderer(JComboBox comboBox) {
    this.comboBox=comboBox;
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setSelectedItem(comboBox.getSelectedItem());
    return this;
    public class EachRowRenderer implements TableCellRenderer {
    protected Hashtable renderers;
    protected TableCellRenderer renderer, defaultRenderer;
    public EachRowRenderer() {
    renderers = new Hashtable();
    defaultRenderer = new DefaultTableCellRenderer();
    public void add(int row,int column ,TableCellRenderer renderer) {
    renderers.put(""+row+column,renderer);
    public Component getTableCellRendererComponent(JTable table,
    Object value, boolean isSelected, boolean hasFocus,
    int row, int column) {
    renderer = (TableCellRenderer)renderers.get(""+row+column);
    if (renderer == null) {
    renderer = defaultRenderer;
    return renderer.getTableCellRendererComponent(table,
    value, isSelected, hasFocus, row, column);
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the FormEditor.
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    table = new javax.swing.JTable();
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    table.setModel(new javax.swing.table.DefaultTableModel (
    new Object [][] {
    {null, null, null, null},
    {null, null, null, null},
    {null, null, null, null},
    {null, null, null, null}
    new String [] {
    "Title 1", "Title 2", "Title 3", "Title 4"
    Class[] types = new Class [] {
    java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
    public Class getColumnClass (int columnIndex) {
    return types [columnIndex];
    jScrollPane1.setViewportView(table);
    getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit (0);
    * @param args the command line arguments
    public static void main (String args[]) {
    new Render ().show ();
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable table;
    // End of variables declaration
    Please help me.

    I ran into the same problem in Java 1.4. The problem is that the JTable is not feeding the initial value to the cell editor. I found the following workaround. You have to override the JTable method prepareEditor() like this:
    <CODE>
    public Component prepareEditor(TableCellEditor editor, int row, int column) {
    Component ret = super.prepareEditor(editor, row, column);
    // Translate column to the data model coordinates by using the
    // identifier. We'll check only for the JComboBox columns (in
    // this example columns 8 and 9).
    int col = 0;
    String id = (String)getColumnModel().getColumn(column).getIdentifier();
    if ( id.equals( tableModel.getColumnName(8) ) )
    col = 8;
    else if ( id.equals( tableModel.getColumnName(9) ) )
    col = 9;
    if (col == 8 || col == 9) {
    String item = (String)tableModel.getValueAt(row, col);
    ((JComboBox)((DefaultCellEditor)editor).getComponent()).setSelectedItem( item );
    return ret;
    </CODE>
    You have to translate from table coordinates to table model coordinates in case the user reorders column - if you don't allow this for your table then you won't have to do this.

  • Jtable - TableModel Problem while setting rowcount

    I have a TableModel which extends from defaulttablemodel
    I have a method to set new rows size.
    First to call setRowCount I re-create the 'data' Object, that initially has 5 x 5 elements
    If I call my function wiht 8 x 5, I get the next fail :
    java.lang.ArrayIndexOutOfBoundsException: 5 >= 5
         at java.util.Vector.elementAt(Unknown Source)
         at javax.swing.table.DefaultTableModel.justifyRows(Unknown Source)
         at javax.swing.table.DefaultTableModel.setNumRows(Unknown Source)
         at javax.swing.table.DefaultTableModel.setRowCount(Unknown Source)
         at geocost.Wtable.w_setrows(Wtable.java:66)
    The code is something like this :
    public void w_setrows(int rows, int cols) {
    TableModelo.w_Gen_Object(rows,cols);     
    TableModelo.setRowCount(rows); ( this is the line 66 )
    private void w_Gen_Object(int numRows,int numCols){                           
    data = new Object[numRows][numCols];
    for (int i=0; i < numRows; i++) {                
    for (int j=0; j < numCols; j++) {
         data[i][j]="";
    Whats wrong ?
    Thank you

    I'm going to explain a little more my problem :
    I'm developing a Jtable Bean, and I want to have an initial control on the number of columns and rows that are going to be view.
    My tablemodel has a getValueAt
    public Object getValueAt(int row, int col) {
                 return data[row][col];             
            }Initially my data object has, by default, 5 x 5 elements. and all is work fine
    The Jtable is correctly viewed.
    If I want to have a 7 x 5 model I :
    1.- I redefine the data object to 7 rows x 5 columns, and it is ok .
    2.- I set the rowcount to 7
    At this point at I get the :
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at org.eclipse.ve.internal.java.vce.launcher.remotevm.JFCLauncher$1.run(JFCLauncher.java:59)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 5 >= 5
         at java.util.Vector.elementAt(Unknown Source)
         at javax.swing.table.DefaultTableModel.justifyRows(Unknown Source)5
    IWAV0052E Invocation Target Exception creating geocost.Wtable
         at javax.swing.table.DefaultTableModel.setNumRows(Unknown Source)
         at javax.swing.table.DefaultTableModel.setRowCount(Unknown Source)
    I must to fire something ? What more I must write ?

  • JTable setPreferredWidth problem, really weird

    Hi,
    I am using the following method to set JTable column width everytime I made some changes to
    the database that JTable connected with.
    //tableView is JTable object
    //displayWidth array is defined to be customized column width int
    public void arrangeCol() {
    tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    TableColumnModel colModel = tableView.getColumnModel();
    //Get the column at index col, and set its preferred width.
    for(int col=0; col<dataBase.getColumnCount(); col++){
    colModel.getColumn(col).setMaxWidth(Globals.maxwidth[col]);
    colModel.getColumn(col).setMinWidth(Globals.minwidth[col]);
    colModel.getColumn(col).setPreferredWidth(displayWidth[col]);
    tableView.repaint();
    However, I am using Visual Cafe 3.0c for development environment, everytime I call this method,
    it will set the column width all to default width 75. But if I run it under Linux, this method works.
    Have you ever run into such problems? Do you have any idea why such a weird problem? How I can fix that?
    Thanks a lot.
    Lei

    I found it and tried it out (to the letter!). Doesn't seem to do anything. There's still this magenta cast. So I guess, double profiling is still going on.
    Since LR works fine, I guess I'll do all my printing using that application then. :(
    Still, it strikes me as odd that LR works fine, and PS does not. This suggests to me that there's a problem with PS and not so much with the Canon driver (although, I absolutely agree it would be wonderful if Canon finally allowed us to truly switch off colour management in their driver).

  • JTable focus problems

    Hi,
    If anyone could help, that would be great. JTables are starting to drive me crazy.
    I have an editable JTable that I have created a CellEditor for. I found that if I am editing a cell and want to tab to the next cell, I have to hit the tab twice. I think it is because the focus was in the cell editor and it needs to get to the table. (If there's a solution to that problem, that would be helpful too).
    I got around that by adding a focus listener to the CellEditor which gives focus to the JTable whenever the CellEditor gains focus. (Does that make sense?) This way, hitting the tab once will move the selected cell. But now when I edit a cell, I don't see the cursor in the textfield becuase the table has focus and the cell editor doesn't anymore. The behavior is correct, but I need to be able to see the cursor. This is my current problem. Any ideas are greatly appreciated.
    Thanks!

    Hi all,
    1. For single key moment, use in the editor of all custom components the method
    public boolan isManagingFocus() {
    return true;
    2. For the immediate cursor on tab use swingutilities.invokelater....
    tblDetail
    .getColumnModel()
    .getSelectionModel()
    .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
    public void valueChanged(javax.swing.event.ListSelectionEvent lse) {
    //Ignore extra messages.
    if (lse.getValueIsAdjusting())
    return;
    int iRow =
    tblDetail.getSelectedRow() >= 0
    ? tblDetail.getSelectedRow()
    : tblDetail.getEditingRow();
    switch (lsm.getMinSelectionIndex()) {
    case 0 :
    SwingUtilities.invokeLater(new FocusGrabber((JComponent) txtTranCode));
    getStatusBar().setStatusMsg1("Enter the Web Transaction Code.");
    if (iRow >= 0) {
    String sCode = (String) tblDetail.getValueAt(iRow, 3);
    if (sCode != null && !sCode.trim().equals("")) {
    txtTranCode.setText(sCode);
    } else {
    txtTranCode.setText("");
    break;
    thanx & regards,
    S.A.Radha.

Maybe you are looking for

  • JCO RFC Provider: "Bean not found" when calling EJB from ABAP via RFC

    Hello, I'm having trouble calling an EJB in a CE 7.1 system from ABAP via RFC. I'm trying to use the JCO RFC Provider service, which mean that I want to expose an EJB so that it can be called via Remote Function Call. I have documented everything, in

  • Gather_plan_statistics hint result not visible

    on my Oracle 11.2.0.1, I tried to use that hint as in example: set autotrace on explain select /*+ gather_plan_statistics */ 'x' from dual; Execution Plan Plan hash value: 272002086 | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time

  • Testing CAD-Desktop interface with CAD-system

    Hi, does anybody know if it is possible to get a CAD-system for free to test the CAD-Desktop interface of SAP? I am not a key CAD user, I just want to look how CAD Desktop works. Regards, Oliver

  • Os x disappeared on server

    ee below I ran a macmini as a server with Lion 10.7.5.  The hard disk is RAID with NAS TM backup and cloned daily to an external hard drive.  In the last few days the macmini started booting from a cloned backup drive instead of from the Server.  I g

  • I can't buy book on iphoto

    after i hit the buy book button the program takes me to a screen where i need to enter the zip code.  the buy book button is not longer highlighted and i have iphoto 11.