How to use keys to position to in JTable

Hi
If i have a JTable showing names in alphabetical order, how do i make it possible to allow user to press key on keyboard and jump to the first name starting with that letter,
for example if the user clicks 'N' jump to first name starting with N
Ashish

* JumpingTable.java
import java.awt.*;
import java.awt.event.*;
import java.awt.event.KeyEvent;
import javax.swing.*;
import javax.swing.table.*;
public class JumpingTable extends JFrame {
    public JumpingTable() {
        initComponents();
    private void initComponents() {
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("Jumping Table: press Alt+J to jump to first name starting with J");
        setSize(600, 300);
        setLocationRelativeTo(null);
        table = new JTable();
        tableModel = new DefaultTableModel();
        table.setModel(tableModel);
        for( int j=0; j<4; j++ ){
            tableModel.addColumn( "Column "+(j+1) );
        for( int j=0; j<names.length; j++ ){
            tableModel.addRow( new Object[]{ names[j], null, null, null } );
        table.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent evt) {
                tableKeyPressed(evt);
        getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
    private void tableKeyPressed(KeyEvent evt) {
        if( evt.getModifiers()==KeyEvent.ALT_MASK
                && evt.getKeyCode()>=KeyEvent.VK_A && evt.getKeyCode()<=KeyEvent.VK_Z ){
            for( int j=0; j<table.getRowCount(); j++ ){
                if( ((String)table.getValueAt(j, 0)).startsWith(evt.getKeyText(evt.getKeyCode())) ){
                    table.changeSelection(j, 0, false, false);
                    break;
    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JumpingTable().setVisible(true);
    private JTable table;
    private DefaultTableModel tableModel;
    private String[] names = new String[]{
        "A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3", "D1", "D2", "D3", "E1", "E2", "E3",
                "F1", "F2", "F3", "G1", "G2", "G3", "H1", "H2", "H3", "J1", "J2", "J3", "K1", "K2", "K3"
}

Similar Messages

  • HT3529 how i use key board

    How i use key board specially  typing of upper case letter

    Press the shift key (looks like an up arrow).  Then press the letter you wish to type in upper case.

  • How to use Key Date in query

    Imagine an invoice was created for a customer on the 1st of January 2008 for £1000
    On the 1st of Feb, he paid $300, owing $700
    On the 1st of Mar, he paid $450, owing $250
    On the 1st of Apr, he paid $250.
    If I run an AR report today the 10th of Aug, I would see he owes nothing. What I want to do is to run the report today based on the 2nd of March and see a debt of £250. I dont want to use the posting date in the selection criteria henceI think this is the case when you use a key date but I’m not sure how to use this in the query properties of BI7. What Characteristic do I need to specify as time dependant? Is there anything else I should consider?

    hi,
    Key Date setting is for the 'time dependent' master data.
    Lets say u have a Characteristic MATERIAL with a time dependent attribute MATERIAL GROUP as follows.
    MATERIAL FROM TO MATERIAL GROUP
    ABD 01/01/1995 12/31/2003 X
    ABD 01/01/2004 12/31/9999 Y
    Depending on what you have for the Keydate, the Material group is selected.
    If your key date is, ex, 06/12/2001 there material group is X. Or if key date is 02/15/2005, material group is Y.
    If you do not enter any value for keydate, system automatically assumes today' date.
    hope it helps..

  • How to use Key Board Key In oracle forms to perform a specific task

    Hello Experts,               I am new In Oracle forms.I am using weblogic server 10.3.5 with oracle forms 11g at windows 7.I have a procedure(say check) under program unit.I have a data block.Now I have need to access Check procedure when I press The 'Ctrl+C'(control +'C' key board key). I have to set this functionality for a single form(module) not for all modules.Please suggest me how to do this by using pl/sql in oracle forms if possible. thank You regards aaditya.

    Hi,
    Its a documentary question, please google for hotkey mapping in forms.
    I hope this is helpful to you Enabling Key Mappings

  • How to use key() function in XSL Mapper file?

    I would like to use the XSLT key() function in an XSL stylesheet in the XSL Mapper designer, but I can find no way to include the <xsl:key> element.
    key() should be supported as it is available in the component palette, but I can't find a way to add <xsl:key> in the designer, and if I add it manually the designer tells me it is not supported.
    This is with Jdeveloper JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660 on Linux.
    Any help appreciated, thanks.

    The usual practice is to leave the XSLT as such. A person skilled in XSLT would know to open the XSLT in source mode if the design view is not supported. Almost most of AIA XSLTs are such and one has to only open them in source view.
    You might want to document this into some document/guide which the person might refer before actually making the changes!
    Cheers,
    - AR

  • How to use Key Flex Fields in Custom Form

    Dear Members,
    I have developed a custom form.
    In my form there is a search criteria for location.
    When ever user wants to query based on the location ,I want to display Asset Location Key Flexfield so that user can choose the respective segements and search the assets.
    Can any one please tell me what is the procedure to be followed to display Key Flex Fields in the custom forms?
    Your inputs will be of great help to me.
    Thanks in advance.
    Best Regards,
    Arun Reddy.

    Hi,
    Please see the note:730068.1 - How To Invoke a DFF from a custom form
    Thanks,
    Ajikumar G

  • How to use keys(f1,f2 etc)

    hi experts ,
    i have a senario . i want to do some logic,  based on keyboard keys ( like f1 , f2 etc )in our basic list . can u help me with some example ?.
    advance wishes ,
    sumanth

    Hi Sumanth,
    You can achieve this using SET PF-STATUS 'ABC'.
    Double click on ABC and it will navigate to SE41(Menu Painter) and give the function codes and assign a function key to the function code.
    Thanks,
    Vinay

  • I am trying to copy and paste a work document into my online class. POP up states that Cut, Copy, and Paste are disabled by my Modzilla broser and that I could use key board short cuts or visit the website.

    '''bold text'''Want to copy & paste word doc onto my online class discussion post. Unable to. I either need directions on how to use key board short cuts. I have visited the Modzilla web site like it also stated but am unable to find an answer to this.

    See:
    *http://kb.mozillazine.org/Granting_JavaScript_access_to_the_clipboard
    *https://addons.mozilla.org/firefox/addon/allowclipboard-helper/

  • Is using key events really that hard?

    I am trying to implement a keyListener for my application, and it seems
    way harder than it should be. My application is simple: A JFrame
    with one button and one JPanel upon which I draw. When I click
    in the JPanel and type, I want things to happen.
    After much looking, it seems I have to not only implement KeyListener,
    but also MouseListener, so when the mouse enters I can call
    requestFocusInWindow().
    That seems to work sometimes, but not when I leave and come back,
    and not always when the application first appears.
    So do I also have to implement FocusListener?
    Why is this so hard to do? MouseListener is very easy to implement,
    but KeyListener seems to be a huge pain in the butt.
    Can someone point me to a simple tutorial or example that just
    has a few swing elements, and processes key events?
    I feel like with Java I often try enough things until it finally works,
    and never really understand why, and what it was that fixed it.
    The documentation and API does not fully describe everything one
    needs to know to use the API "properly". Am I the only one frustrated
    by this? I have programmed in Java/Swing for years, and JUST LAST
    WEEK discovered that when implementing paint in swing, one should
    override paintComponent and not paint. But then why does overriding
    paint usually work? There are too many quirks in Java that let you
    get away with doing things wrong, and then suddenly, your application
    is broken. It wouldn't be so bad if the API was more clear on some of
    these suble issues.
    Thanks,
    Chuck.

    How to Use Key Bindings

  • Focus problem using key event

    Hi!
    There is an application I've created uses key event that needs your help.
    As you know, that setting 'Mnemonic' to a JButton object makes the button accessible by a key mentioned in the parameter as the following ->
                   OkButton.setMnemonic(KeyEvent.VK_O);Now, pressing 'Alt' and 'O' keys together will do the same action as the 'OKButton' does.
    But as of me, I think pressing two keys together is not a complete handy job.
    So, is there any code that will do the same, by pressing only the 'O' key ?
    Ok! I know that there is something to be taken care of; that is, if I want the button to react by pressing only the 'O' key the button must be in focus [value returned by the method [code]isFocusable() for the button must return true.]
    Then how the 'Mnemonic' works ?!! When 'Mnemonic' do something, button does not have any focus.
    Only, I press the Alt+O and the work done successfully! No need to take care wherever the focus is. So, is there any way to do alike, where I don't have to manage the focus subsystem?? I would only press the 'O' key and the task will be done.
    Please send a sample code. Thanks!

    I suggest you look into Key Bindings:
    "How to Use Key Bindings"
    http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html
    Here is a short demo program that uses Key Bindings to do what you describe:
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    public class PressOTest extends JFrame {
        public PressOTest() {
            super("Press O or C");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            // Action that will be associated with the OK button and with
            // the 'O' key event
            Action okAction = new AbstractAction("Ok") {
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(PressOTest.this, "Ok!");
            // Action that will be associated with the Cancel button and with
            // the 'C' key event
            Action cancelAction = new AbstractAction("Cancel") {
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(PressOTest.this, "Cancel!");
            // Register Key Bindings for the 'O' and 'C' keys:
            InputMap im = getRootPane().getInputMap(
                    JComponent.WHEN_IN_FOCUSED_WINDOW);
            ActionMap am = getRootPane().getActionMap();
            im.put(KeyStroke.getKeyStroke( KeyEvent.VK_O, 0 ), "ok");
            am.put( "ok", okAction );
            im.put(KeyStroke.getKeyStroke( KeyEvent.VK_C, 0 ), "cancel");
            am.put( "cancel", cancelAction );
            // Create and add OK & Cancel buttons:
            JButton okButton = new JButton(okAction);
            JButton cancelButton = new JButton(cancelAction);
            Box box = Box.createHorizontalBox();
            box.add( Box.createHorizontalGlue() );
            box.add( okButton );
            box.add( Box.createHorizontalStrut(10) );
            box.add( cancelButton );
            box.add( Box.createHorizontalGlue() );
            getContentPane().add( box );
            setSize(300, 300);
            setLocationRelativeTo(null);
        public static void main(String[] args) {
            new PressOTest().setVisible(true);
    }

  • How to detect key board event

    HI,
    How to detect keyboard event (Like CTRL key press shift key press) in Swing�any can any body suggest classes and interface for that�.
    Thanks

    [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to use Key Bindings

  • How to detect key navigation in JTable

    Hi,
    I have a problem with JTable's events. When the user presses the mouse's left button on a cell, a mouseClicked event is generated, and my program works fine. But when the user moves from cell to cell with the cursor keys or the tab key, no mouseClicked event is generated, and my event code doesn't execute. I have seen listeners like TableColumnModelListener, but I don't want two or more events at the same time: i.e. if I go from cell 1,1 to cell 2,2, I just want one event, not one for the column and another for the row. I just want ONE event for "selection change", originated by mouse or keyboard. What should I use?
    I'm using Java 1.4.
    Thanks.

    [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to use Key Bindings

  • How to use checkboxes in jtable ?

    I am trying to use checkboxes in
    JTable,I set the property in the jtable column to boolean.The proplem is that i do no know how to use this property in java program.My intension is that,I will have a java form and a java button on it,by clicking the button, i will have to write a code,for example a code that fetches records from a table and displays them on the jtable(on the user interface),when I select the check box corresponding to any row,It should let me either delete or edit that row and this modification has to be reflected to the table in the database. At this time,i can fetch and display but i can not delete or modify any row because I do no know how to use the check box inside the jtable.
    Thank you for your help!

    Multi-post: http://forum.java.sun.com/thread.jspa?threadID=5273661&tstart=0

  • How to use the validation work in Both TAB and Mouse keys in Forms6i

    Hi,
    I have a validation script once it's validated it should execute the query.But using When-Validate-Item i can't use execute_query.I am able to use the validation in Key-Next-Item trigger but if the user moves the cursor using mouse then it's not working.
    How to use the validation script working in Both Scenarios(Tab and Mouse keys).
    Can anyone please give inputs to rectify the above issue?.

    So you have multiple fields, but on at least one of them if it's valid you immediately want to execute the query?
    You could create a hidden field in a control block Query_Now default 'N'. In a WHEN-VALIDATE-ITEM on your item, if it's determined to be valid, then set Query_Now to 'Y'.
    In a WHEN-NEW-ITEM-INSTANCE at block level, check if Query_Now is 'Y'. If it is then execute the query (and set it back to 'N').

  • How to use a key file in the FTP Task using and SSL connection

    In the past I have used this code to set the FTP pass word in an FTP component task in SSIS.
    Does anyone know how to use a Key file in an SSL connection to download a file from an FTP site?  If not can you tell me where I can get the C# code examples to learn how to create a script task or if there is another way in SSIS to download large files
    from an SSL FTP site?  Thank you for any help offered.
    public void Main()
    ConnectionManager FTPConn;
    FTPConn = Dts.Connections["FTPServer"];
    FTPConn.Properties["ServerPassword"].SetValue(FTPConn, Dts.Variables["FTPPassword"].Value);
    Dts.TaskResult = (int)ScriptResults.Success;
    Antonio

    You can use SFTP for this.
    This is a way of implementing SFTP in SSIS using standard tasks 
    http://visakhm.blogspot.in/2012/12/implementing-dynamic-secure-ftp-process.html
    also see
    http://blog.goanywheremft.com/2011/10/20/sftp-ftps-secure-ftp-transfers/
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for