Installing new keyboard actions to the JList

Hi I want to install replace the arrow keys and use the numpad keys to go next and previous item in JList also I dont want to show to Popup bar in gui but in the the following code it is not working for the when I install KeyboardActions to the List
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import javax.swing.InputMap;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.basic.BasicListUI;
import sun.swing.DefaultLookup;
public class ListOneItem extends JFrame implements ListSelectionListener {
     private static final long serialVersionUID = 1L;
     public ListOneItem() {
          final String[] numbers = {"one", "two", "three", "four", "five", "six", "seven"};
          final JList list = new JList(numbers);
          list.setVisibleRowCount(1);
          list.setSelectedIndex(0);
          list.addListSelectionListener(this);
          final JScrollPane scrollPane = new JScrollPane(list);
          scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
          scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
          getContentPane().add(scrollPane, BorderLayout.NORTH);
          final MyBasicListUI listUI= new MyBasicListUI();
          list.setUI(listUI);
     class MyBasicListUI extends BasicListUI {
          @Override
          public void installKeyboardActions() {
               // get the input map
               final InputMap _im = (InputMap) DefaultLookup.get(list, this, "list.ancestorInputMap");
               // set extra keys for "selectNext" and "selectPrevious" actions
               _im.put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD9, 0), "selectNextRow");
               _im.put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD6, 0), "selectPreviousRow");
               // install the updated InputMap
               super.installKeyboardActions();
     public void valueChanged(ListSelectionEvent e) {
          final JList list = (JList) e.getSource();
          list.ensureIndexIsVisible(list.getSelectedIndex());
     public static void main(String[] args) {
          final ListOneItem frame = new ListOneItem();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(200, 200);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
}it gives the null pointer exception for the following code
final MyBasicListUI listUI= new MyBasicListUI();
list.setUI(listUI);
where I am trying to add new Keyboard Actions to the JList

While getting InputMap use key *"List.focusInputMap"* instaed of *"list.ancestorInputMap"* in installKeyboardActions() method.
final InputMap _im = (InputMap) DefaultLookup.get(list, this, "List.focusInputMap");Only to register new keystrokes for existing actions you don't need to have custom look and feel class. Instead modify the InputMap after list creation.
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import javax.swing.InputMap;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.basic.BasicListUI;
import sun.swing.DefaultLookup;
public class ListOneItemModified extends JFrame implements ListSelectionListener {
     private static final long serialVersionUID = 1L;
     public ListOneItemModified() {
          final String[] numbers = {"one", "two", "three", "four", "five", "six", "seven"};
          final JList list = new JList(numbers);
          list.getInputMap(JList.WHEN_FOCUSED).remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0));
          list.getInputMap(JList.WHEN_FOCUSED).remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0));
          list.getInputMap(JList.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD9, 0), "selectNextRow");
          list.getInputMap(JList.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD6, 0), "selectPreviousRow");
          list.setVisibleRowCount(1);
          list.setSelectedIndex(0);
          list.addListSelectionListener(this);
          final JScrollPane scrollPane = new JScrollPane(list);
          scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
          scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
          getContentPane().add(scrollPane, BorderLayout.NORTH);
          //final MyBasicListUI listUI= new MyBasicListUI();
          //list.setUI(listUI);
//     class MyBasicListUI extends BasicListUI {
//          @Override
//          public void installKeyboardActions() {
//               // get the input map
//               final InputMap _im = (InputMap) DefaultLookup.get(list, this, "list.focusInputMap");
//               // set extra keys for "selectNext" and "selectPrevious" actions
//               _im.put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD9, 0), "selectNextRow");
//               _im.put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD6, 0), "selectPreviousRow");
//               // install the updated InputMap
//               super.installKeyboardActions();
     public void valueChanged(ListSelectionEvent e) {
          final JList list = (JList) e.getSource();
          list.ensureIndexIsVisible(list.getSelectedIndex());
     public static void main(String[] args) {
          final ListOneItemModified frame = new ListOneItemModified();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(200, 200);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
}

Similar Messages

  • Windows 7 Corrupted after installing new keyboard

    Installed a new keyboard on my Dell 1525 Inspiron computer. Good news the new keyboard works perfectly, bad news, Windows 7 will not launch. I have run the diagnostics and it all says it is fine. I have run the recovery mode and auto repair, and it comes
    up and says a recent hardware installation should be removed and try again. So I removed the new keyboard and reinstalled the old keyboard, but did not fix it. Try going back to a previous backup and it did not fix it either. Now what? Should I reinstall Windows
    7? I don't have a recovery disc or the original disc since I upgraded from XP to W7 by downloading it.  I hate spending $90 dollars on new software as old as the computer is, but it still works really well, which is why I bought the keyboard. Help!!!!!

    Hi BeckyLaWR,
    Is the keyboard a USB device ? Have you tried to choose the "Last known good configurations" option to have a check ? Does machine boot well without the new keyboard ?Can we boot into safe mode ?
    There is a possibility that the driver installed for the keyboard is corrupted.It is recommended to download the driver from the manufacturer website for the new keyboard.
    Best regards

  • HELP: Taking forever to install new keyboard langu...

    I tried to install two new keyboard languages on my Lumia 1020: 
    1. Chinese Traditional BoPoMo
    2. Chinese Traditional Handwriting
    It's already over 45 min after I added these two languages, but the status for both languages are still showing Preparing download...
    Is this normal? 
    Please help comfirming it. 
    Thank you.

    Lot many users have reported this issue..
    1. You may try rebooting the phone..
    2. Confirm that Battery Saver mode (under 'settings') is OFF 
    ..and select only 1 download at a time.

  • Touchpad vanishes after installing new keyboard

    I'm trying to figure out what I could have done to cause this problem.
    A couple of keys fell off of my keyboard, and a few others were sticking, so I called Lenovo support and they sent me a new one (it came in about two days!) which I promptly installed.  The new keyboard works great!  However, now my touchpad doesn't work.  It is as if it doesn't exist - I looked in the Mouse program (from the Control Panel), and the Touchpad is not even showing up in it.  I tried reinstalling the UltraNav drivers, but sadly, it did not work.  Luckily the trackpoint works just fine, so I'm not completely ruined.
    At any rate, the really strange thing is that my fingerprint reader still works just fine.  I mean, it tends to be a little tempermental (that or my fingerprints change on a daily basis), but it's always been like that.
    I tried opening it back up and unplugging the touchpad/fingerprint scanner part and then plugging it back in, and also took a look at it to see if anything had clearly fallen off, but it seems just fine.  I didn't drop it or do anything else to it when I took out the wrist-rest/touchpad to install the new keyboard.
    Any thoughts?
    More information on my system:
    14.1" Thinkpad T61 (8891-CTO), in warranty (a full warranty with the extra add-on).
    I'm running Windows XP Pro (SP2)
    I bought this laptop around August 2007
    I'm hoping I can fix this myself without having to order new parts, although that hope is rapidly fading.  Thank God Lenovo's support is so easy to deal with, especially with ESC - I used to have a Dell and it was nightmarish dealing with their tech support.

    John:
    Reinstall the old keyboard. If it works you likely purchased a dud. If you have problems with it, too, let us know.
    cornelius

  • Cursor not moving/wor​king after installing new keyboard

    I have just finished replacing the keyboard on my HP G72 due to spilling some water on the keyboard a few days ago & some of the keys not working after laptop dried out. However, I find that things are not as they should be as I just can't get the cursor to move. I don't use a mouse & rely on the touchpad. I've tried removing the keyboard & reinstalling a few times  but all to no avail & wonder if anybody can give me some advice, even if it's that the keyboard itself might be faulty & I need to buy another one. I don't want to just assume  there is a problem with this new keyboard only to find out that the problem lies elsewhere & that there are other things I should be doing or trying.
    I did have to install a new keyboard on this laptop sometime last year afer having a similar accident with water spillage, but installing the new one that time was pretty much a piece of cake, I followed the onscreen guides I'd looked at & everything was perfect once I'd installed the new keyboard. 
    Thanks if you can advise.
    This question was solved.
    View Solution.

    Hi,
    If possible try with a USB mouse for sometime. That way if the cursor works then you can try reinstalling the touchpad drivers which might fix the issue. If cursor doesnt work with external mouse also then problem could be hardware related.
    Sometimes repeating the process of installing the keyboard all over again also helps.
    Note:
    If you have HP Support Assistant installed on the computer(The Blue Question Mark) then open it ==> Complete all pending Updates & Tuneups==> Restart and Check. It may solve your problem
    Although I am an HP employee, I am speaking for myself and not for HP.
    **Click on “Kudos” Star if you think this reply helped** Or Mark it as "Solved" if issue got fixed.

  • I had to get a new keyboard and now the keys in the upper row are not working appropriately. How can I fix this problem?

    My keyboard stopped working so I went to the apple store to replace it with another one. Now I am back home and the keys at the very top are not working correctly (volumn  F12 shows the dashboard, F11 takes the screen up and away, F8 pause button shows spaces, etc.). What should I do to correct this problem - I assume I probably need to download some type of softwear but what? I have a Mac OS X  Version 10.5.8 desktop - 2.66 GHz Intel Core 2 Duo processor.

    All new keyboards need Snow Leopard 10.6.8 and above for full functionality.
    Rather short-sighted of Apple perhaps, but that seems to be a trend these days.
    I'm afraid the only fix is to upgrade to SL. Personaly, I'd take it back and get a refund and seek an older keyboard or a third-party one elsewhere.

  • Installing new Secuirty provider on the WebLogic Server

    Hi Everyone,
    I think you guys can find a solution for the problem i'm facing in configuring
    the weblogic server. I'm evaluting the server a possible client and need to relpy
    to him regarding the possible purchase before the mid of next week.
    Problem: The problem i'm facing is as follows. I wrote a web service, I'm trying
    to install a new service provider on the server. I did copied the jar files to
    the java_home\jre\lib\ext directory and did made the change to the java.security
    file as suggested in the "Professiona Java Security" book by wrox publication
    . But when i run the code it doesn't works on the BEA Server. Even though i tested
    successfully on the java server.
    The client wwritten in Java works fine. but the server, when tries to make call
    to service, it fails on the call to the Encryption algorithm class.
    Does any one of you have a solution for this problem. I'm waiting for your reply.
    Thanks in advance?
    Sumit
    SETA Corporation
    Virginia

    Hi Boris,
    Looks like you have not run the post upgrade script for 10.1.3.4.
    You need to install SOA 10.1.3.4 Basic Installation. Then start following : http://download.oracle.com/docs/cd/E12524_01/core.1013/e13058/weblogic.htm#BHCIIBFB
    You basically, first install 10.1.3.4 basic SOA install, Apply the Opatch 7337034 (HOTPLUG: SOASUITE 10.1.3.4 ON WEBLOGIC 9.2 - CHANGES FOR HOTPLUGGABILITY). Install WLS 9.2 MP3.
    Now, Download the Oracle SOA Suite 10.1.3.4 WebLogic Server 9.2 : patch : 7490612.
    Then , Modify the following mandatory installation properties in the Weblogic_SOA10134_Base\SOADomain.properties file as per the documentation above.
    Cheers
    Anirudh Pucha

  • How to install new font file in the device when deploying J2ME application?

    i would like to know how to install the new font file in the device when deploying J2ME application, side-by-side.
    Is that possible to seamlessly install the new font file with the application .jar package.
    thnx.

    No, there is no way of installing new fonts.

  • Problems with installing new itune, different from the problems described.

    Ok, so this morning when I was trying to access itunes, it said "error, send error report" or something like that. I retried it several times, but it would not work. So I uninstalled it and installed the new version. Then, I when I was trying to download it, it said something is wrong with my "Windows Installer Package"...and it just skips installing itunes... Please help me, thank you.

    Then, I when I was trying to download it, it said something is wrong with my "Windows Installer Package"...and it just skips installing itunes
    instead of running the install on line, download and save a copy of the iTunes installer to your hard drive, and run the install from there.
    if you still get the message then, could you post back with the precise text of the message?

  • After clearing cash on mac applications won't lunch any more..I tried to delete apps like VLC player with app cleaner and again download and instal new but it's the same..goes for all apps that are not originally part of Yosemite. Please advise me?!

    After clearing cash on my mac ( Go to folder: ~/Library/Caches and clear all, than to Library/Cashes and clear all again) applications won't lunch any more..I tried to delete apps like VLC player, firefox.. with app cleaner and again download and install the new one but it's the same..goes for all apps that are not originally part of Yosemite. I have done this cash clean up very often on Maverick without any problems. This time I done it again because I could not open my web site, the server has blocked me and I was trying everything including deleting cash from mac. Please advise me what to do..?!? Thanks in advance.

    It sounds like you may have multiple problems, but none of them are likely to be caused by malware.
    First, the internet-related issues may be related to adware or a network compromise. I tend to lean more towards the latter, based on your description of the problem. See:
    http://www.adwaremedic.com/kb/baddns.php
    http://www.adwaremedic.com/kb/hackedrouter.php
    If investigation shows that this is not a network-specific issue, then it's probably adware. See my Adware Removal Guide for help finding and removing it. Note that you mention AdBlock as if it should have prevented this, but it's important to understand that ad blockers do not protect you against adware in any way. Neither would any kind of anti-virus software, which often doesn't detect adware.
    As for the other issues, it sounds like you've got some serious corruption. I would be inclined to say it sounds like a failing drive, except it sounds like you just got it replaced. How did you get all your files back after the new drive was installed?
    (Fair disclosure: I may receive compensation from links to my sites, TheSafeMac.com and AdwareMedic.com, in the form of buttons allowing for donations. Donations are not required to use my site or software.)

  • I am trying to install new CAD software, but the computer will not open the ".dmg" file so the installation can begin.  H  E  L  P  !  !  !

    I am trying to install ViaCAD v7.2 for Mac, but when I try to open the ".dmg" file, it will not open, so the installation never begins.

    I was trying to find the system specifications ViaCAD v7.2 but wasn't too successful. However I found the App Store has V8.0.2, have you already purchased 7.2? If so perhaps you could request an exchange for a more current version.

  • Installed new harddrive, what are the steps necessary to load operating sy

    replaced hard drive in power book g 4 titatium(sp) What is next steps that needed to be taken so I can load OS X

    Hi
    Place the original disks that came with the laptop into the optical drive and hold down the 'C' key. The rest is fairly obvious from there. If you don't have the original installer disks but have a 'Universal' installer disk, use that instead. If you don't have any installer disks at all for some reason you're going to have to buy some.
    All of this assumes your optical drive is at least a DVD-ROM and still working? If that's not the case there are other methods you could use to install the OS. The hardware you have means you can't install 10.6 (Snow Leopard) as 10.6 will only install on Intel Macs. If you have a set of gray coloured installer disks loaned to you by a friend or acquired in some other means which are not machine specific to your hardware you won't be able to use those either.
    Tony

  • HELP! I tried installing new printer software. The progress screen stayed at 0% so I forced quit. But the installing drivers screen remained. I manually shut off the computer. When I restarted it went from start up screen to terminal with multiple errors.

    The final message says (my-name-computer):/I have no name!
    I tried safe start but it just shuts down after the start ip screen.
    I tried starting with the OS disk in but didn't help.
    Please someone help!

    Oh Oh, you may need a stronger Disk Repair tool, or the DRive may be dying!
    You must repair the HD, your best bet is likely DiskWarrior.
    BTW, you might enjoy these DiskWarrior review/recommendations...
    http://discussions.apple.com/thread.jspa?messageID=9645801&#9645801
    http://discussions.apple.com/thread.jspa?messageID=10541019#10541019
    http://discussions.apple.com/thread.jspa?messageID=11918925&#11918925
    http://discussions.apple.com/thread.jspa?messageID=12684129#12684129
    http://discussions.apple.com/thread.jspa?messageID=12744794&#12744794
    http://discussions.apple.com/thread.jspa?messageID=12912879#12912879
    You must repair the HD,  if Disk Utility or fsck should fail to repair it, your best bet is DiskWarrior from Alsoft, you'll need the CD to boot from if you don't have another boot drive...
    http://www.alsoft.com/DiskWarrior/
    Your best bet is DiskWarrior, you need the CD/DVD though.
    http://www.alsoft.com/DiskWarrior/
    But others that may work…
    Drive Genius…
    http://www.prosofteng.com/products/drive_genius.php
    TechTool Pro…
    http://www.micromat.com/index.php?option=com_content&task=view&id=31&Itemid=83

  • Weird Audio problem since installing new SSD and Reinstalling the OS and Upgrading Ram

    I have a really strange problem in Premiere ( well the same thing happens with he native files outside premiere too! )
    Some of my .wav and .wma files sound corrupt. At first i thought it was a buggy project file.
    Then i checked some other files from projects waiting to be done and they were the same, heart attack time.
    So i copied the apparent bad file to my laptop and it plays fine!
    Then when i check some audio files from finished projects on my PC they sound corrupt too! And obviously they were fine when i actually finished the projects.
    I've tried it in Premiere CC2014 and CS5, but it's not the program i now know.
    I Googled "Audio codecs Windows7" but all the options appear to be malware , has anyone any ideas? IS there a codec pack i could try?
    I'm running Win 7 Pro
    i7 960 @ 3.2
    24 gb ram
    Nvidia GTX 480
    Thanks,
    Ronan

    Got this sorted.

  • How to Switch the default Keyboard to New Keyboard app

    Hi, I want to install new Keyboard from Android app and downloaded while trying to install the new key board am getting option to change keyboard type but am unable to change the same 
    Kindly guide 
    Regards,
    Ananthan.K

    I don't believe that is possible, sorry.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

Maybe you are looking for

  • Business systems  for Soap to file scenario

    Hi Experts,    I am working on a soap to file scenario.Which type of business systems shall i  create i.e Third party,As ABAP,As Java etc.Please suggest. Thanks Veeru

  • HELP - Buffered Reader

    Below is a portion of my program, its a simple app, that is supposed to read a policy number, and then display the results. I can't get it to read the file, or output onto the app. Any help would be appreciated. the file is called loans.txt and a lin

  • What WordStar 3.01 can do in Mail Merge that Pages '09 can't.

    I have a Bento database. I want to print contra dances from it on 3x5 index cards. I can save the database as a Numbers worksheet with all the data I want on it. I SHOULD be able to use the fields from that Numbers file to create a Pages document tha

  • Catching COMBO BOX item changed in VALIDATE event

    Hi expert, I need to catch the item changed event for a combo box. below the code: <B1Listener(BoEventTypes.et_VALIDATE, False)> _ Public Overridable Sub OnAfterValidate(ByVal pVal As ItemEvent)             Dim form As Form = B1Connections.theAppl.Fo

  • Function to color Text in Console Program?

    Does anybody knows of a function to color Text in Console Program. Example textbackcolor(2);//c++ system.out.println("Heres is a color text"); And how do you clear the console window in java in c++ it is clrscr().