Removing cursor from JTable

I want to use a series of key bindings to perform operations on a JTable.
Unfortunately, it seems that as long as the 'cursor' (square box around the current cell) is present on a cell in a JTable, then pressing any key will cause that cell to be entered for editing. This is preventing me from using the key binding shortcuts I wish to use to perform operations on the JTable. The shortcuts only work when there is no 'cursor' on the table (ie. before any cell is initially selected).
I have used the "clearSelection()" method of class JTable to deselect all highlighted cells in the table, but this does not remove the cursor. Is there a way to do this?

Hi,
you can make it possible by implementing your custom TableModel as Follow.
javax.swing.table.DefaultTableModel dModel = new
// @param - model - Vector with Row Data
// @param- getColumnHeader() - ColumnModel
javax.swing.table.DefaultTableModel(model,getColumnHeader()){
            public boolean isCellEditable(int rowIndex, int mColIndex) {
                return false;
        };Timir

Similar Messages

  • Add and remove columns from JTable

    Help me please!
    A try to remove column from JTable. It's removed, but when I try to add column in table, then I get all old (removed early) columns + new column....
    I completely confused with it.....
    Here is my code for remove column:
    class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             table.getColumnModel().removeColumn (tableCModel.getColumn (HowManyColDelete [ i ]));
                   else
                          JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         }

    It's little ex for me, I just try understand clearly how it's work (table models i mean). Here is code. All action with tables take place through menu items.
    My brain is boiled, I've try a lot of variants of code, but did't get right result :((
    It's code represent problem, which I've describe above. If you'll try remove column and then add it again, it will be ma-a-a-any colunms...
    I understand, that my code just hide columns, not delete from table model....
    But now I have not any decision of my problem...
    Thanks a lot for any help. :)
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    import javax.swing.table.DefaultTableModel;
    class JTableF extends JFrame
         Object [] [] data = new Object [0] [2];
         JTable table;
         DefaultTableModel model;
         String [] columnNames = {"1", "2"};
         TableColumnModel cm;
         JTableF()
              super("Table features");
              setDefaultLookAndFeelDecorated( true );
              setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              JMenuBar MBar = new JMenuBar();
              JMenu [] menus =  {new JMenu("A"), new JMenu("B")};
              JMenuItem [] menu1 =  {new JMenuItem("Add row"), new JMenuItem("Delete row", 'D'),  new JMenuItem("Add column"), new JMenuItem("Delete column")};
              menu1 [ 0 ].addActionListener(new AddL());
              menu1 [ 1 ].addActionListener(new DelL());
              menu1 [ 2 ].addActionListener(new AddC());
              menu1 [ 3 ].addActionListener(new DelC());
              for (int i=0; i<menu1.length; i++)
                   menus [ 0 ].add( menu1 [ i ]);
              for (int i=0; i<menus.length; i++)
                   MBar.add(menus );
              JPanel panel = new JPanel ();
              model = new DefaultTableModel( data, columnNames );
              table = new JTable (model);
              cm = table.getColumnModel();
              panel.add (new JScrollPane(table));
              JButton b = new JButton ("Add row button");
              b.addActionListener(new AddL());
              panel.add (b);
              setJMenuBar (MBar);
              getContentPane().add(panel);
              pack();
              setLocationRelativeTo (null);
              setVisible (true);
         class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             int vizibleCol = table.convertColumnIndexToView(HowManyColDelete [ i ]);
                             tableCModel.removeColumn (tableCModel.getColumn (vizibleCol));
                        //cm = tableCModel;
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         class AddC implements ActionListener
              public void actionPerformed (ActionEvent e)
                   //table.setColumnModel(cm);
                   Object NewColumnName = new String();
                   NewColumnName = JOptionPane.showInputDialog ("Input new column name", "Here");
                   int i = model.getRowCount();
                   int j = model.getColumnCount();
                   Object [] newData = new Object [ i ];
                   model.addColumn ( NewColumnName, newData);
         class AddL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int i = model.getColumnCount();
                   Object [] Row = new Object [ i ];
                   model.addRow ( Row );
         class DelL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int [] HowManyRowsDelete = table.getSelectedRows();
                   if (HowManyRowsDelete.length !=0)
                        for (int k = HowManyRowsDelete.length-1; k>-1; k--)
                             model.removeRow (HowManyRowsDelete[k]);
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Row is not selected!");
         public static void main (String [] args)
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        JTableF inst = new JTableF();

  • White patch after removing row from JTable

    I am working with JTable and removing item from table on clicking on button but after removing row there is white Patch on that row. I don�t want to show this white patch.
    I did repaint table but that is also not working.
    Any thoughts !!!!!!!

    javax.swing.SwingUtilities.invokeLater(new Runnable(){
                public void run(){
                  museTable.setBackground(Color.black);//your color here
              });

  • Problem removing rows from JTable

    Hello,
    I'm having an issue with a JTable that I'm using. At one point in my application, I want to remove all the rows from the table and regenerate them (from a database). When I try to remove the rows and do nothing else, they remain in the table. The rows are being removed from the model, as I have verified this in code, but the display does not refresh at all.
    I am using custom renderers to change the background color of a cell based on its value, and I disabled them to see if that was the problem, but alas, it is not.
    Any suggestions or ideas why this may be occurring?

    I am using model.setRowCount(0); to clear the model, however the display never refreshes. Then you are doing something wrong because its that simple. Only a single line of code is required.
    Perhaps I should have included this in my original post.Actually, you should have included demo code in your original post. That way we don't have to guess what you are doing.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • How to remove text from JTable ...........

    AOA
    How to remove the text from cells of JPanel. Just to refresh the GUI.
    regards

    How to provide meaningful subject?
    The subject of this thread does not match what you are asking in the body.
    To set the value of a cell in a JTable, you can simply call setValueAt().
    Read the API to find the method parameters.

  • Remove row from JTable

    I have a JTable, and after selecting a row of the JTable a dialog opens for me to perform an action. But when I close the dialog I want that the row I have selected has disapeared, that means that I want to refresh the view removing the selected row. How can I do this?

    DefaultTableModel.removeRow(...);

  • How to remove a row from JTable

    Hi!
    I'm used to remove rows from JTables getting the model and doing a removeRow(num) like this:
    ((DefaultTableModel)jTable1.getModel()).removeRow(0);
    But with ADF and JDeveloper the model says it's a JUTableBinding.JUTableModel but its not accessible.
    How to remove a row in Jdeveloper 10.1.3.4.0?

    Or maybe is just better to refresh data in the jTable but I do not know either like doing it.

  • LV2009: Graph- Copy Data moves/removes cursors

    Using a right click->Copy Data seems to move or remove cursors from the image copied to the clipboard.  Anyone know of a workaround that doesn't involve screen cap and edit?
    PrtScn result:
    Copy Data result:
    Other results show the cursor changing its value, but only in the vertical axis.
    Thanks,
    Joe Z.

    This forum post is over three years old. In order for the community to better answer your question could you please post a new question and link this older post to it. This will allow it to appear nearer to the top of the postings. Have a great day.
    Alex D
    Applications Engineer
    National Instruments

  • Remove record in database from Jtable?

    I want to delete row in databse, but don't know how to add field to primary key Jtable like hidden field,
    Can you show me or any difference way to solve this?

    There are two ways to hide a column (that I know of):
    1) Set the columns widths to 0. I don't like this approach because because the 'hidden' column still requires a tab.
    2) Remove the TableColumn from the TableColumnModel. This is my preferred approach.
    Here is a simple example using both approaches, You determine which approach you like best:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableColumnHide extends JFrame
         public TableColumnHide()
              String[] columnNames = {"Identifier", "Student#", "Student Name", "Gender", "Grade", "Average"};
              Object[][] data =
                   {new Integer(1), "Bob",   "M", "A", new Double(85.5) },
                   {new Integer(2), "Carol", "F", "B", new Double(77.7) },
                   {new Integer(3), "Ted",   "M", "C", new Double(66.6) },
                   {new Integer(4), "Alice", "F", "D", new Double(55.5) }
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              //  Hide column by setting minimum width
              JTable table1 = new JTable(model);
              table1.getColumnModel().getColumn(0).setMinWidth(0);
              table1.getColumnModel().getColumn(0).setPreferredWidth(0);
              table1.setPreferredScrollableViewportSize(table1.getPreferredSize());
              JScrollPane scrollPane1= new JScrollPane( table1 );
              getContentPane().add( scrollPane1, BorderLayout.WEST );
              //  Remove columns from TableColumnModel
              JTable table2 = new JTable(model);
              TableColumnModel columnModel2 = table2.getColumnModel();
              columnModel2.removeColumn( columnModel2.getColumn( 0 ) );
              table2.setPreferredScrollableViewportSize(table2.getPreferredSize());
              JScrollPane scrollPane2 = new JScrollPane( table2 );
              getContentPane().add( scrollPane2, BorderLayout.EAST );
              JPanel north = new JPanel( new GridLayout(1, 2) );
              north.add( new JLabel("Width = 0") );
              north.add( new JLabel("Remove Table Column") );
              getContentPane().add(north, BorderLayout.NORTH );
         public static void main(String[] args)
              TableColumnHide frame = new TableColumnHide();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }Since we 'hid' the first column, try tabbing from the last column to the first. Notice which approach requires 2 tabs before the appropriate cell gets highlighted.

  • How do I stop the cursor from spontaneously going to Line one space one in Notes?

    How do I stop the cursor from spontaneously going to Line one Space one in Notes?
    I am currently working on a MacBook Pro connected by Wi-Fi or Blue Tooth to my 16GB iPhone 4S; and supposedly to iCloud.  I install every upgrade on each computer till the computer can take no more.  My current MacBook Pro continues to accept upgrades.
    I have been dealing with Address Book foibles since it first came out and the problems seem to get worse rather than resolved.
    Problem #1: When a Company Name is checked to take precedence over a personal name the record/file does not surface during searches.  This has happened for years on all my Macs, including most recently my MacBook Pro and its predecessor PowerBook G4.  How do I fix this?
    Problem #2: The Printing Defaults for Address Book Files are not useful and I can find no way to change them to my own preferences once and for all.  I must reset them for every file every time I choose to print a file.  Is there some way to set the defaults to MY preferences and only occasionally reset them according to my needs?
    Problem #3:  When entering information in "Notes" the cursor randomly and spontaneously goes to line one space one as I am entering information.  How do I stop this?  Then when I cut and paste the misplaced text to where it belongs it may or may not return to once again begin at line one space one and following.
    Problem #4:  When Printing a Record/File from Address Book I would like to use the whole 8.5" x 11" page.  Instead it prints on an 8.5" x 11" page in three columns.  Is there a way to format the output?  I have not found one and the Mac 'Geniuses' do not know of any.
    Problem #5:  Subsequent to one of the upgrades in the last year or so, the search feature does not work.  (I have had this computer since May 2011).  No matter what I type in the search line I am stuck in the 'All' Directory.  To find anyone or anything I must scroll through the address book manually.  Is there a fix to this?
    Problem #6:  Sometimes, when I try to sync my MacBook Pro and my iPhone, the records simply duplicate.  How d I undo this without manually deleting the duplicates?
    Problem #7:  Does anyone know of a third party Address-Book-type App that is better than the Apple version and can easily import over 3000 contacts information?

    '''I had the same problem when I updated to firefox 4. This is how i fixed it:'''
    The problem seems to be caused by the 'New Tab Homepage' add on. So:
    # Disable or remove the 'New Tab Homepage' add on and restart firefox.
    # Download and install the firefox add on called 'NewTabURL' and restart firefox.
    # Click on the Options button for NewTabURL and uncheck 'Select location bar after loading new tab'
    # Under the 'Default URL for new tabs' heading, choose 'Home Page'
    # Click on the Save button.
    Hopefully, problem solved!

  • How to make text STAY up after removing mouse from button?

    Hello!
    I honestly hope that this thread title makes sense. Allow me to explain my predicament.
    Someone has created a map where there are little colored buttons over building locations. The buttons were made so that when you hover your cursor over them, they will bring up a little chat bubble (like the ones you see in comics) with the appropriate street address text. What I cannot figure out is how to, after removing the cursor from over a button, make the text bubble stay put so that those who see the map can highlight then copy and paste the street address from it.
    Is there any advice?

    It kinda depends on what version of actionscript you're using, but one that may work for AS2 and AS3 is to use setTimeout to call a function that does what your rollout code currently does... meaning in your rollout function you use: setTimeout(callFunction, x-seconds)... where callFunction is a function that contains what your rollout function did originally.

  • How do I remove images from Notes app?

    How do I remove images from Notes app?
    I sometimes find that, when cutting and pasting text from the web, an image is also copied (pretty much at all times I try and avoid this, but sometimes the selection process doesn't allow for fine enough control - e.g. a whole block of content may be selected, rather than just the few words I'm trying to copy).
    I then find, once it's part of my note, that I cannot select the unwanted image and remove it. Can anyone tell me if this is something that can be done, and if so... how?
    Thanks, Sebastain

    Hi Drew & Kilgore*
    Thanks for your replies. I also have and use Simplenote, although I went off it for a while, when it started crashing all the time on me. It seems to be more stable again now, so I'll start using it more regularly again, perhaps.
    I am, obviously, disappointed that one can't simply select ANY object within a Notes document and choose to delete it. As I rather suspected, the only solution is an annoying workaround. Apple stuff seems to get more like this as time goes by. At least in my experience.
    I solved the issue my own way in the end, but I guess it was close to your 1st idea DR, and your 2nd option, KT: I basically cut and pasted everything above, and then everything below, the image, and pasted both chunks of text into a new note. So it took two passes, and left me with the original note just displaying the image, which I then trashed.
    Tapping to the right of the image followed by deletion was what I hoped & expected would work. But instead the image stayed put and the text below the cursor would simply slide along the right hand side, moving upwards as I deleted! Most bizarre, to my mind at least.
    Anyway thanks for the feedback. But, for anyone else that might want to know how to do this, the answer is: NO, you can't select and delete an image once it's in one of your notes!
    * I quite recently watched the rather strange Bruce Willis / Nick Nolte 'Breakfast of Champions' movie... I think I still prefer the book to the film!

  • Removing record from secondary database

    Could soembody please explain - if I'm removing entry from secondary database using a cursor, will that entry be removed from primary database as well, or I need to remove it explicitly?

    looks like it does, as stated in javadocs, so nevermind ;)

  • Populate a REF CURSOR from regular cursor...

    Hi all,
    I apologize if the answer to this is somewhere...I've been looking on the web for sometime and can't find an answer to the following problem. I have a Significant Events database that contains network based issues and problems. As problems are detected on the network an SE is issued and published. As the SE records are updated, NEW records are entered into the table and "linked" back to the original. Each update results in a new row. Thus, an SE with two updates would have a total of 3 lines. When the SE gets closed (set the column CLOSED to SYSDATE), only the "original" SE is closed, any updates are left open...aka, the CLOSED column is left null.
    That said, I need a way to get the original and/or latest updated SE rows from the table. Thus, I am trying to use a PL/SQL package. The PL/SQL "must" return a REF CURSOR as the results are being passed to a client process.
    My initial approach was within a PL/SQL procedure, I have an SQL statement that returns the SE originals. Once in that cursor I need to do the following:
    - Attempt to fetch any linked SE rows.
    - if no rows then
    - add the original to the REF CURSOR.
    - else
    - find latest SE update
    - add latest SE update to REF CURSOR.
    - end if
    My Question is : How do I manually "add" a row to a REF CURSOR?
    If this is not possible, is there a way to populate a REF CURSOR from maybe another construct like:
    TYPE ian_se_record is RECORD (
    se_id number
    ,linked_se_id number
    ,submitted date
    ,updated date
    ,closed date
    ,segroup varchar2(150)
    ,incident_start_time varchar2(150)
    ,business_units_affected varchar2(150)
    ,officenum varchar2(1500)
    ,sedetails varchar2(4000)
    TYPE ian_se_table is table of ian_se_record index by binary_integer;
    With the above construct I could:
    - Fill ian_se_table with the process described above.
    - And finally select off ian_se_table into the REF CURSOR?
    Any help would be greatly appreciated,
    adym

    Hi michaels,
    I've put your solution in place, but can't seem to get it to run. The two types were moved out of the package and into real types as you said. Here's the function, for brevity, I've remove some of the less important code:
    function ian_se_fetch return sys_refcursor
    is
        p_csr_events            sys_refcursor;
        cursor csr_items is
            select
                 se_id
        ...removed for brevity...
        /* END : csr_items  */
        ian_se_row     ian_se_record;
        ian_se_tbl     ian_se_table;
        l_lng_index    number;
        l_lng_linked   number;
        l_lng_id       number;
    begin
         * OPEN : Open the main cursor of originals...
        for the_item in csr_items loop
             * CHECK : Check for any updates to the original...
            l_lng_linked := 0;
            select count(*)
            into l_lng_linked
            from sig_se_t src
            where src.linked_se_id = the_item.se_id;
            l_lng_id := 0;    /* reset the se-id    */
            /* SE original...no linked records yet.    */
            if ( l_lng_linked = 0 ) then
                l_lng_id := the_item.se_id;
            /* SE updates...one or more updates are present.    */
            else
                begin
                    select
                         se_id
                    into l_lng_id
                    from sig_se_t src
                    where src.linked_se_id = the_item.se_id
                      and rownum = 1
                    order by updated desc; /* latest update    */
                exception
                    when too_many_rows then
                        l_lng_id := the_item.se_id;
                    when others then
                        l_lng_id := 0;
                end;
            end if;
            if ( l_lng_id != 0 ) then
                select
                     se_id
                    ,linked_se_id
                    ,submitted
                    ,updated
                    ,closed
                    ,segroup
                    ,incident_start_time
                    ,business_units_affected
                    ,officenum || decode( nvl(impact,'1')
                                      ,'1',''
                                      ,decode(impact
                                          ,'NA', ''
                                          ,':' || impact
                                  )                           impact
                    ,sedetails
                into ian_se_row.se_id
                    ,ian_se_row.linked_se_id
                    ,ian_se_row.submitted
                    ,ian_se_row.updated
                    ,ian_se_row.closed
                    ,ian_se_row.segroup
                    ,ian_se_row.incident_start_time
                    ,ian_se_row.business_units_affected
                    ,ian_se_row.officenum
                    ,ian_se_row.sedetails
                from sig_se_t src
                where src.se_id = l_lng_id;
                l_lng_index := nvl(ian_se_tbl.last,0)+1;
                ian_se_tbl(l_lng_index).se_id                   := ian_se_row.se_id;
                ian_se_tbl(l_lng_index).linked_se_id            := ian_se_row.linked_se_id;
                ian_se_tbl(l_lng_index).submitted               := ian_se_row.submitted;
                ian_se_tbl(l_lng_index).updated                 := ian_se_row.updated;
                ian_se_tbl(l_lng_index).closed                  := ian_se_row.closed;
                ian_se_tbl(l_lng_index).segroup                 := ian_se_row.segroup;
                ian_se_tbl(l_lng_index).incident_start_time     := ian_se_row.incident_start_time;
                ian_se_tbl(l_lng_index).business_units_affected := ian_se_row.business_units_affected;
                ian_se_tbl(l_lng_index).officenum               := ian_se_row.officenum;
                ian_se_tbl(l_lng_index).sedetails               := ian_se_row.sedetails;
            end if;
        end loop;
         * REF CURSOR : Open the ref cursor on the dataset...
        if ( nvl(ian_se_tbl.last,0) = 0 ) then
            p_csr_events := null;
        else
            open p_csr_events for
            select *
            from table (cast ( ian_se_tbl as ian_se_table ));
        end if;
        return p_csr_events;
    end;Here's the test. I keep getting the same error ORA-06530:
    SQL> variable v refcursor;
    SQL> exec :v:=pkg_ian.ian_se_fetch;
    BEGIN :v:=pkg_ian.ian_se_fetch; END;
    ERROR at line 1:
    ORA-06530: Reference to uninitialized composite
    ORA-06512: at "N0002501.PKG_IAN", line 131
    ORA-06512: at line 1
    SQL> print v
    ERROR:
    ORA-24338: statement handle not executedOther things I tried:
    - The ian_se_fetch() function was a procedure using an in out parameter...same error.
    - Wrote a small anonymous block and tried to LOOP/FETCH. Same ORA-06530 error.
    P.S. Line 131 of pkg_ian is the SELECT ... INTO ian_se_row.se_id, ...
    Any help would be greatly appreciated,
    tia,
    adym
    Message was edited by:
    alink

  • Adding/removing columns in jtable

    Hello everyone,
    i was looking for a way to add/remove columns from a jtable. The way i envision it working is... Initially have a predefined number of columns, of these only show the user say 5 of those on startup. but then provide a drop down (or list box etc) of the other column headings, so that when the user selects one... it adds it to the jtable. also to remove ..... is there a way to have a pop-up when the user right-clicks the table header and put a option to remove that column there? if not what is the best way to trigger a remove of a column? So i need a way to keep track of all the columns in case the user wants to add it again. anyone know how this can be done or any part of it?

    I need a intutive way for the user to remove a column from the gui (like with adding could be a dropdown box with column headers as labels).Create a custom ComboBoxModel. This model would simply contain TableColumns and display the header value in the combo box. The first combo box would display the currently showing columns. When you click on an item in the combo box:
    a) remove the TableColumn from the TableColumnModel
    b) remove the TableColumn from the model
    c) add the TableColumn to the "hidden" combo box model
    The same basic logic (but in reverse) would then apply when you click on the "hidden" combo box.

Maybe you are looking for

  • Itunes 8.1 out-of-tune

    Since i've upgraded to itunes 8.1. im experiencing nothing but problems. i don't know what the apple experts claim that itunes 8.1 does, but is much much slower for me. Allow me to elaborate, i'm using time capsule store all of my music library. I re

  • Using an OLE container to store MS word files

    Hello, We are using OLE containers in Forms 6 to store word documents. Occasionally documents seem to be coruppted and can not be opened. I exported document back to a file useing TOAD but the file seems to have a bunch of extra header info added by

  • Adding a photo gallery

    Ater a search, I'm more confussed than ever. I have the site to the point where I'm ready to add photos. I'm a photographer( I have PS cs2 and a trial DW CS4) I would like to display 5-10 photos on my index page in the form of an automated slide show

  • Mighty Mouse (Bluetooth) NOT Fully Functional

    After installing Mac OS X 10.7 (Lion), the Might Mouse BT used with a MacBook 2.26 GHz Intel Core 2 Duo only functions as a pointer but it cannot select with a click .Battery power is okay. The Mighty Mouse was fully functinal with Mac OS 10.6.8 on t

  • Satellite L850-13R wakes up from standby with no reason

    My L850 wakes up from standby every 10-20 minutes and after some time goes to standby again. All power options are set as they should be (that means no wake on battery and even no wake up on power). Problem is that this is my business notebook and I