Can't get focus in JTabbedPane

I have several tabs in a JTabbedPane. Each tabb is hotkeyed to "1","2","3", etc. The left and right arrows keys are remapped in this way:
mainTabbPane.registerKeyboardAction (PrintHi, KeyStroke.getKeyStroke (KeyEvent.VK_LEFT, 0), JComponent.WHEN_FOCUSED);
And I have an AbstractAction like this:
AbstractAction PrintHi = new AbstractAction ()
public void actionPerformed (ActionEvent e)
System.out.print ("Hi");
The problem is this. On each tabb I have several JTables, JLabels, JTextAreas and other stuff showing information. When I select/edit something, like a JTable, the arrow hotkeys stop function. It seems to me as the last selected JTable still has the focus and won't let it go. So when I press arrow keys, the arrow keys is directed into the JTable instead? Dont know if it so, but that is the impression I get.
The weird thing is, the hotkeys for the different tabs works. If I press ALT + 1, the first tabb pops up. But the JTable is still selected. And the arrow keys is directed into the JTable.
Anyone has pointers and hints?

Ok, I apologize for not having explained my question completely. This is exactly what I am trying to do:
When I press the arrow keys, they will print out a message. After I go to the 3rd panel and choose a combobox, I go back to the first panel and the arrow keys suddenly stop working. Why???
(It is as if the 1st tabbpane has lost the focus, and cant get it. The focus is stuck on the JComboBox. When I switch back to 1st panel from comboboxpanel, I want the 1st panel to get focus, and hence the arrow keys will work again. When I choose the 3rd panel the arrow keys can stop work, that is ok. The important thing is that when I switch back to the first panel, the arrow key must work again. In an ideal world, the arrow keys are tied to panel 1 and panel 2. Hence, when I switch to panel 3, the arrow keys will stop work. When I choose panel 1 again, the arrow keys must work.)
Sorry for making it difficult for you to help me. I really appreciate your effort. The thing is, I am starting a software company and am supposed to deliver the first version tomorrow monday. And everything works ok, except this CENSORED hot keys. Making me really stressed. Well, anyway I have specified the question better now. I really hope you can point me in the right direction on how to solve this problem.
Is there a way for the shown panel to get focus? When I switch to panel 1, it gets the focus? Or should I try to tie the arrow keys to panel 1? Or should I tell the combobox to not respond to arrow keys? Which way to go?
Please execute the program and see if it is only me having a problem?
package test;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.KeyStroke;
public class SSCCEE extends JFrame {
     private static final long serialVersionUID = 1L;
     JTabbedPane tabbpane = null;
     public static void main(String args[]) {
          new SSCCEE();
     public SSCCEE() {
          tabbpane = new JTabbedPane();
          tabbpane.insertTab("tabb 1", null, new MyTablePane(), "tooltip1", 0);
          tabbpane.setMnemonicAt(0, KeyEvent.VK_1);
          tabbpane.insertTab("tabb 2", null, new MyTablePane(), "tooltip2", 1);
          tabbpane.setMnemonicAt(1, KeyEvent.VK_2);
          tabbpane.insertTab("tabb 3", null, new MyComboboxPane(), "tooltip3", 2);
          tabbpane.setMnemonicAt(2, KeyEvent.VK_3);
          this.add(tabbpane);
          setHotKeys();
          this.pack();
          this.setVisible(true);
     private void setHotKeys() {
          AbstractAction PrintHi = new AbstractAction() {
               private static final long serialVersionUID = 1L;
               public void actionPerformed(ActionEvent e) {
                    System.out.print("Hi ");
          AbstractAction PrintHo = new AbstractAction() {
               private static final long serialVersionUID = 1L;
               public void actionPerformed(ActionEvent e) {
                    System.out.print("Ho ");
          tabbpane.registerKeyboardAction(PrintHi, KeyStroke.getKeyStroke(
                    KeyEvent.VK_LEFT, 0), JComponent.WHEN_FOCUSED);
          tabbpane.registerKeyboardAction(PrintHo, KeyStroke.getKeyStroke(
                    KeyEvent.VK_RIGHT, 0), JComponent.WHEN_FOCUSED);
class MyComboboxPane extends JPanel {
     private static final long serialVersionUID = 1L;
     private JComboBox aCombobox = null;
     MyComboboxPane() {
          aCombobox = new JComboBox();
          aCombobox.addItem("Meow");
          aCombobox.addItem("Voff");
          this.add(aCombobox);
          aCombobox.addActionListener(new java.awt.event.ActionListener() {
               public void actionPerformed(java.awt.event.ActionEvent e) {
                    JComboBox cb = (JComboBox) e.getSource();
                    System.out.println((String) cb.getSelectedItem());
class MyTablePane extends JPanel {
     private static final long serialVersionUID = 1L;
     private JTable aTable = null;
     MyTablePane() {
          aTable = new JTable(
                    new String[][] { { "This", "is", "cell 13" },
                              { "a", "Test", "cell 23" },
                              { "cell 31", "cell 32", "cell 33" } }, new String[] {
                              "Col 1", "Col 2", "Col 3" });
          this.add(aTable);
}

Similar Messages

  • Item - Can't set value on item because the item can't get focus.  [66000-15

    hi i created one text box in purchase order form and asign the choose from list.l when i choose in edit box its show the following error-- Item - Can't set value on item because the item can't get focus
    Dim lonHeadDatasource As SAPbouiCOM.DBDataSource
    lonHeadDatasource = oOrderForm.DataSources.DBDataSources.Item("OPOR")
    oNewItem1 = oOrderForm.Items.Add("EditDS", SAPbouiCOM.BoFormItemTypes.it_EDIT)
                        Dim oCFLs As SAPbouiCOM.ChooseFromListCollection
                        Dim oCFLCreationParams As SAPbouiCOM.ChooseFromListCreationParams
                        Dim oCFL As SAPbouiCOM.ChooseFromList
                        oCFLs = oOrderForm.ChooseFromLists
                        oCFLCreationParams = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams)
                        oCFLCreationParams.MultiSelection = False
                        oCFLCreationParams.ObjectType = "INTORDER"
                        oCFLCreationParams.UniqueID = "CFL1"
                        oCFL = oCFLs.Add(oCFLCreationParams)
                        oItem = oOrderForm.Items.Item("4")
                        oNewItem1.Top = 95
                        oNewItem1.Height = oItem.Height
                        oNewItem1.Width = 140
                        oNewItem1.Left = 125
                        oEdit = oNewItem1.Specific
                        oEdit.DataBind.SetBound(True, "OPOR", "U_EditDS")
                        oOrderForm.Items.Item("EditDS").Specific.ChooseFromListUID = "CFL1"
                        oEdit.ChooseFromListAlias = "U_ID"
    Item events
    Try
                If pVal.BeforeAction = False Then
                    If (pVal.FormType = 142) Then
                        Select Case (pVal.ItemUID)
                            Case "EditDS"
                                Select Case (pVal.EventType)
                                    Case SAPbouiCOM.BoEventTypes.et_GOT_FOCUS
                                    Case SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST
                                        Dim bonCflEvents As SAPbouiCOM.ChooseFromListEvent
                                        Dim bonCflList As SAPbouiCOM.ChooseFromList
                                        Dim bnnstrUID As String
                                        Dim bonDTTable As SAPbouiCOM.DataTable = Nothing
                                        bonCflEvents = pVal
                                        bnnstrUID = bonCflEvents.ChooseFromListUID
                                        bonDTTable = bonCflEvents.SelectedObjects
                                        bonCflList = oOrderForm.ChooseFromLists.Item(bnnstrUID)
                                        If pVal.BeforeAction = False Then
                                            If oOrderForm.Mode <> SAPbouiCOM.BoFormMode.fm_FIND_MODE Then
                                                If Not (bonDTTable Is Nothing) Then
                                                    If bonCflList.UniqueID = "CFL1" Then
                                                        If pVal.ItemUID = "EditDS" Then
                                                            Dim value As String = Nothing
                                                            oOrderForm.Items.Item("EditDS").Specific.value = bonDTTable.GetValue(0, 0)
                                                        End If
                                                    End If
                                                Else
                                                    lonHeadDatasource.SetValue("EditDS", lonHeadDatasource.Offset, "")
                                                End If
                                            End If
                                        End If
                                End Select
                        End Select
                    End If
                End If
            Catch ex As Exception
                SBO_Application.SetStatusBarMessage(ex.Message)
            End Try
    Thanks & Regards
    B.Narain

    Hi
    Instead of   oOrderForm.Items.Item("EditDS").Specific.value = bonDTTable.GetValue(0, 0) the following
    lonHeadDatasource.SetValue("U_EditDS", 0, bonDTTable.GetValue(0, 0))
    Regards
    Arun

  • Why my textfield can not get focus?

    I put a textfield on the first tab of a tabbed panel. I need this textfield to get the focus when I open the first tab. I tried to use grabfocus() method in the constructor of class, but it does not work. Does anybody know why? and how can I solve it?
    Thanks!

    No, I didn't call grab/requestFocus on the event thread.
    My code is like this:
    public class GeneralPane extends JPanel {
    JPanel ltPane;
    private JTextField txtCountry;
    public GeneralPane() {
    initComponents();
    private void initComponents(){
    setLayout(new BorderLayout());
    //Add another Panel to contain Labels and Text fileds
    ltPane = new JPanel();
    FocusListener mFL = new FL();
    txtCountry = new JTextField("US", 20);
    //this listener is used to store the data in the textfield into a variable
    txtCountry.addFocusListener(mFL);
    // add the textfield into ltPane
    mUtil.insertTextPane(txtCountry,ltPane);
    //txtCountry got focus
    //txtCountry.setFocusable(true);
    ltPane.requestFocus();
    //txtCountry.requestFocusInWindow();
    Then in the main program, I create an instance of this class and then use addTab(...) function into the my tabbedPanel.
    The logic is simple, but the textfield still couldn't get focus when I open the tabbedPanel.

  • Can't get focused a JTextField within a JTable cell

    I have a table and I placed a cell editor with a JText field on it for all cell editing,
    I want to do things when the focus is lost or gained and my app works fine when a cell is double clicked or f2 is pressed, but when a cell is selected (without double clicking) and just begin typing it produces no focus gained event.
    I tried by calling grabFocus method of that jTextField within the overriden prepareEditor method of the JTable but it doesn't get focus (doesn't even gains and loses it :s )
    Does anyone have an idea of how to force this component to grab focus?
    Thanks

    Hai,
    dont add the FocusListener to the EditorComponent.
    Try to use the JTable Functions - like this:
    import javax.swing.event.ChangeEvent;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.EventObject;
    import javax.swing.*;
    public class Test extends JFrame
         JTable table;
         JTextArea text;
         JScrollPane scroll;
         JTextField cellTextField;
         Test()
              DefaultTableModel model = new DefaultTableModel();
              cellTextField = new JTextField();
              text = new JTextArea();
              text.setEditable(false);
              scroll = new JScrollPane();
              scroll.setViewportView(text);
              table = new JTable(model){
                   @Override
                   public Component prepareEditor(TableCellEditor editor, int row, int column) {
                        text.append("Better use this to Start Edit!\n");
                        return super.prepareEditor(editor, row, column);
                   @Override
                   public void editingStopped(ChangeEvent e) {
                        text.append("Better use this to Stop Edit!\n");
                        super.editingStopped(e);
              model.addColumn("Column 1");
              model.addColumn("Column 2");          
              model.addRow(new String [] {"Cell 1", "Cell 2"});
              table.setCellSelectionEnabled( true );
              table.getColumnModel().getColumn(0).setCellEditor( new DefaultCellEditor(cellTextField));
              table.getColumnModel().getColumn(1).setCellEditor( new DefaultCellEditor(cellTextField));
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(table, BorderLayout.NORTH);
              getContentPane().add(scroll, BorderLayout.CENTER);
              setSize(300, 300);
              setVisible(true);
              setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
         public static void main(String[] args)
              new Test();
    }

  • Can't get focus to address bar in new tab

    I have tried everything said in previous posts and unfortunately i cant get it to focus the address bar.
    I have tried uninstalling all adons, restarted in safe mode, this should be like this automatically, but for some reason it isn't. Can i change something in about:config?
    Ty
    /A.R

    You might need to reinstall Firefox to repair program files, but first, do you want to try a different new tab page: just a blank page?
    (1) In a new tab, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (2) In the search box above the list, type or paste '''newtab''' and pause while the list is filtered
    (3) Double-click the '''browser.newtab.url''' preference and change from ''about:newtab'' to ''about:blank'' and OK that change.
    You can test immediately with Ctrl+t to see whether that makes any difference.

  • Can you get focus for an invisible JFrame?

    I'm writing a program where I use a JFrame for user input, and, after receiving input, the JFrame goes invisible, leaving the desktop clear while the program continues processing in the background. I want the same JFrame to be called back with user keyboard input (e.g. F12), but I don't know how to get KeyListener to work because I cannot obtain focus on the invisible JFrame. Is this possible?
    If not, is there a similar way to work around the problem?
    Any help is appreciated, thanks!

    I don't think that you can have focus on an invisible frame (though I'm not sure) but a goos way around would be to show a small dialog that says "Currently working, press a key to go back to main screen" and add a key listener to this dialog instead of the invisible frame.
    But if you want to work in the background, maybe you'll have to run the dialog on a new thread for both to work at the same time.
    Hope it helps

  • JTextField and JTextArea don't get focus occuasionally

    I am developing a Java Swing Applet. At edit mode, JComboBox, JCheckBox, JRadioBox, and JButton work fine, but JTextField and JTextArea can't get focus occuasionally while I click them.
    Anyone has idea?
    Thanks

    Thank you Himanshu,
    but that's not exactly what my issue is. This link describes the undesired effect of ending up outisde of the player window and in the browser.
    My problem is kind of the opposite. When I launch the page in the html file I cannot use the tab key to get to any of the controls in the captivate window. I'm stuck in the browser unless I click on the captivate window. That is not acceptable if we want it accessible without using a mouse. I found a way to make it work for chrome like I stated above, but not in FF. Do you have any ideas for this?
    Thanks!
    Monique

  • Can I get rid of parts of the JRE for my app?

    I am trying to figure out how to easily deploy a stand-alone desktop Swing application. It's more like Microsoft Word than the typical Swing business app that deals with networks and databases. I'd like to make this easily downloadable by regular people, like a 10-year old who has installed an IM client, or a 70-year old who has downloaded the latest version of a browser, i.e., just download an installation file and then click to install in the relatively standard manner in which Windows apps are installed.
    What I am definitely trying to avoid is making the user go to Sun's Java distribution website, which is written by computer geeks for computer geeks. If a potential user sees that, they'll get confused, give-up, and I'll have lost a potential user.. Since a Swing application that is developed and tested using an earlier version of the JRE won't necessarily work with a later version, I can't make the assumption that as long as the latest JRE is installed on the user machine, everything is fine. As far as I can tell, I need to download a self-contained version of the JRE that I developed with in order to guarantee that the app will run as expected. I also don't want the user to have to download a 15 Mb 1.5 JRE, or the purported 50 Mb 1.6 JRE just to be able to run my little program. (I'm really starting to see why there are no popular Java desktop apps.)
    So my question is - if I compile my application down into machine code from binary code, does anyone know if can I get away with running it with a stripped-down JRE? I'm wondering if I can get rid of parts of the JRE that deal with things like interpreting bytecode, networking or database access, none of which I need to worry about. Sun's legal department might not like this, but is this at all technically feasible? I'm actually happy to hear about any ideas regarding shrinking the size of the distribution. Thanks.

    I voted for the enhancement request. It is almost exactly what I am concerned with.
    I am a big fan of Excelsior Jet. I tried out the free version about a year-and-a-half ago, and was pretty happy with it. It was actually the only machine-code compiler I tried out of several that worked. If I ever get to the point where I can start selling my app, I expect that I'll use it. I've been checking the website every so often since then, and reading about the next version, where a JRE can be included in the distribution. That helped spark my original question. While the worry about making sure my application had the right JRE version will be solved, it still bugs me that I have to ship so much unnecessary JRE code. (I blame Sun for that, not Excelsior Jet.) I was wondering if it was at all technically feasible to strip out the unnecessary code, irrespective of the legal issues. When compiled to byte-code, my program is under 1 MB. When I compiled it to machine code under JDK 1.4, it was about 5 MB. I imagine that compiling to machine-code with the included 1.5 JRE, after compression, will result in a size in the 15-20 MB range. And this after refactoring my program to where it's about 1/3 it's original size. I'm really worried about the direction this is going, and I don't even want to think about what including the 1.6 JRE will require.
    Where did you read that I've been programming Java since '97. I was a contractor at Sun between 1995 and 1997, and started working on Java 1.0 apps back then, but I don't ever remember mentioning that. If you asked because you're thinking I should know more about JVM/JRE issues, you're probably right, but I focus almost exclusively on higher-level application and GUI/Graphics issues. The deep-down Java stuff makes me break out into a cold-sweat.

  • Can't get Typekit to work with localhost (also, another weird issue with copy+paste)

    Hi!
    I've searched through the other posts already, and I *think* I've tried all the solutions, but I still can't get the typekit fonts on my machine.
    I'm trying to use the "orator-std" font.  In the "kit editor", in the "kit settings -> kit settings" tab I have for name "localhost" (w/o quotes) and for domains just "127.0.0.1" (w/o quotes).
    Then (AFTER saving the settings from that tab), I go back into edge animate, I start a new font by clicking that + sign next to "fonts", in the "library" tab.  I set the "font fallback list" to ' "orator-std",sans-serif ' (w/ quotes, w/o single quotes), and then go back to the open browser and go to the "embed code", copy both lines of javascript, go back to edge animate, and... nothing.  It won't let me change ANY text in this box anymore after the window loses focus.  I have to press "cancel" and try again.  So this time, I just type in the orator-std... blah blah, same as last time, but paste in the code successfully as it was already in the clipboard and I didn't need to make the window lose focus.  Okay, so I click "Add font", and apply the font to my text.  Nothing happens.
    Huh... well the "Font's from T" picture is showing up in the bottom right of my screen, so that's odd.  I go to preview in chrome, still ugly old sans-seriff there, also with the "Font's from T" logo in the bottom right.
    I figure "okay, probably just takes a second... or a minute... or w/e like the message said."  Well this was at least an hour ago, so something is still wrong.
    I would love to just delete the font and start from scratch... maybe something got screwed up along the way and it would fix things to just start from scratch.  Well... "sorry" says edge animate... can't let you delete that!  In the "libarary" tab, there's only one font visible, it says "orator-std,sans-serif" (w/o quotes).  If I right click it, the only option is "delete" and it's greyed out.
    I tried doing one with arial instead of sans-serif just now, still not working, but everything shows up in arial now instead of sans-serif... so that's something I guess.
    Apologies if this is just a simple problem that I'm just somehow not grasping.  Please accept this legitimate bug report as payment... the er copy paste bug, I mean...
    Thanks!
    Trevor

    Hi Trevor,
    I'm sorry you ran into trouble here. Typekit can be used locally. However there are some necessary steps that if left out, will cause the fonts not to render. In order to use Typekit locally, you've got to:
    1. Be running a local server when testing your site in the browser. You can tell if you're running a local server by the URL of the local site. If it starts with: file:// then you are just viewing the local file in a browser and not running it from a local server.
    If the local URL starts with: http:// then you're running a local server.
    2. The domain of your local server has to be part of the domain list in your Kit. So, if your local server uses: localhost, you'll need to add this to your Kit's domains.
    I hope this helps. If you have any further questions, feel free to reach out to us directly: [email protected]
    Cheers,
    Benjamin

  • Server can't get to internet

    File server:
    SunFire X4140
    OpenSolaris
    SunOS 5.11 svn_111b
    Hi,
    I'm new to sysadmin, and very new to solaris. Any help would be very much appreciated - I'm trying to get a file server back on the internet that a couple dozen people are waiting for! It's part of a small ad hoc cluster in a rack. It had been working fine every since I started to take care of things part-time 6 months ago. The other day it just dropped off the internet. Then, when I tried a console GUI login at that point it froze up (the GUI, at least). I had to use the serial management port to do a graceful reboot.
    There is an external switch to which all servers are connected, and a local switch used by several (but not all) of the servers in the rack with the file server. I've inherited this system and am unsure of the full rationale of the local switch, but imagine it's for faster local file transfer.
    Other servers in the rack are online, BUT they're running linux variants. The file server runs opensolaris to be able to use zfs. There's another opensolaris server in the rack but it's stuck booting up kubuntu, looking for an NFS mount and I can't get it to skip the mount - haven't focused on this b/c it's non-essential.
    The file server system (see above) boots and I can login, but cannot get online. I get these errors at boot:
    1) The 'opensolaris' graphical boot screen (with the moving orange progress bar) seems to hang. After several minutes I hit return to enter CLI mode. At that point I see errors 2 and 3. I can login.
    2) WARNING: /pci@0,0/pci10de,cb84@2 (ohci0): Connecting device on port 2 failed
    I'm not sure if this is the built-in NIC's, or built-in rear USB ports - or something else. Haven't been able to determine for sure. The rear USB ports don't seem to be working - I have to plug the keyboard into the front usb port to get it to work, so maybe it's the usb.
    3) in.ndpd[429]: interface nge[0|1|2|3] has been removed from the kernel. in.ndpd will no longer use it
    The server has 4 built-in ethernet ports, no others. There are three ethernet cables plugged in - two for the external switch, one for the internal switch. The error for a given interface is only generated when there is a cable plugged into the port, and regardless of whether it goes to local or external switch. Then it repeats the error every minute for 2 of the 3 cables - haven't found a pattern as to which.
    If I connect only one cable, either to internal or external switch, I don't get this error. But, I still don't IPv4 address, see below.
    "ifconfig -a" output (transcribed)
    (cables are plugged into ports 1,2 and 3 (as labeled on the hardware) but not 0):
    lo0: flags=2001000849 <skip>
         inet 127.0.0.1 netmask ff000000
    nge0: flags=1004803<UP,BROADCAST,MULTICAST,DHCP,IPv4> mtu 1500 index 2
         inet 0.0.0.0 netmask ff000000
         ether 0:21:28:3d:6d:2
    nge1: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 3
         inet 0.0.0.0 netmask ff000000
         ether 0:21:28:3d:6d:3
    nge2: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 4
         inet 0.0.0.0 netmask ff000000
         ether 0:21:28:3d:6d:4
    nge3: flags=1000842<BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 5
         inet 0.0.0.0 netmask ff000000
         ether 0:21:28:3d:6d:5
    lo0: flags=2002000849 <skip>
         inet6 ::1/128
    nge[1|2] [changes to the nge that was not most recently reported as removed by in.ndpd error.]: flags=2004841<UP,RUNNING,MULTICAST,DHCP,IPv6> mtu 1500 index [3|4]
         inet6 fe80::221:28ff:fe3d:6d0[3|4]/10
         ether 0:21:28:3d:6d:4
    Phew. Thanks very much for any help or suggestions!
    -Michael
    Edited by: 979786 on Jan 3, 2013 11:04 AM
    Edited by: 979786 on Jan 3, 2013 11:08 AM
    Edited by: 979786 on Jan 3, 2013 11:10 AM
    Edited by: 979786 on Jan 3, 2013 12:09 PM

    There might be some eventual replies to your inquiry, but you may need to realize that an online forum is the worst place to hope for help for business-critical issues. The anonymous nature of such a forum is that there is no obligation that there ever be a reply and there is no guarantee that replies are correct for your issue.
    Such a system as you have described needs to be on a support contract (even though OpenSolaris isn't a supportable OS -- it's a discontinued Open Source experiment ). You need to use your support contract to contact Technical Support and open a Service Request to figure out why you have no IPV4 IP addresses, nor any current IPV6 IP addresses.
    ... but I do give you props for at least trying.
    :)

  • Can't get keyboard command to work right

    Hello,
    I'm trying to get 2 different sets of keys to move a character in a game. "WASD" and the arrow keys. The arrow keys work fine, but I can't get the character to move to the left witht the "A" key after I press the "D" key. Can anyone tell me what to do? I think it might have something to do with the focus? But I don't know anything about that......Here's my code:
    public function Player(model:GameModel, stage:Object, playerX:Number, playerY:Number) {
                                  // constructor code
                                  _gameModel = model;
                                  _stage = stage;
                                  xPos = playerX;
                                  yPos = playerY;
                                  _stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, false, 0, true);
                                  _stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler, false, 0, true);
    private function keyDownHandler(event:KeyboardEvent):void
                                  if (_gameModel.gameMode != "play") return;
                                  processKeyDown(event);
                        private function keyUpHandler(event:KeyboardEvent):void
                                  if (_gameModel.gameMode != "play") return;
                                  processKeyUp(event);
                        internal function processKeyDown(event:KeyboardEvent):void
                          if(event.keyCode == Keyboard.A)||
                                   (event.keyCode == Keyboard.LEFT))
                                    walk = true;
                            acceleration_X = -aSpeed;
                          if((event.keyCode == Keyboard.D)||
                                   (event.keyCode == Keyboard.RIGHT))
                                    walk = true;
                            acceleration_X = aSpeed;
                          if((event.keyCode == Keyboard.UP)||
                                   (event.keyCode == Keyboard.W))
                           jump=true;
                          if((event.keyCode == Keyboard.DOWN)||
                                   (event.keyCode == Keyboard.S))
                                    //crouch = true;
                        internal function processKeyUp(event:KeyboardEvent):void
                            if (event.keyCode == Keyboard.LEFT
                            ||event.keyCode == Keyboard.RIGHT||
                         event.keyCode == Keyboard.A
                            ||event.keyCode == Keyboard.D)
                            acceleration_X = 0;
                                   walk = false;
                          if((event.keyCode == Keyboard.UP)||
                                   (event.keyCode == Keyboard.W))
                             jump = false;
                           if((event.keyCode == Keyboard.DOWN)||
                                   (event.keyCode == Keyboard.S))
                             acceleration_Y = 0;
                             //crouch = false;

    Here is the top half of the class, not including the variable declarations at the beginning:
    public function Player(model:GameModel, stage:Object, playerX:Number, playerY:Number) {
                                  // constructor code
                                  _gameModel = model;
                                  _stage = stage;
                                  xPos = playerX;
                                  yPos = playerY;
                                  _stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, false, 0, true);
                                  _stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler, false, 0, true);
                                  _stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener, false, 0, true);
                                  _stage.addEventListener(MouseEvent.MOUSE_DOWN, shootListener, false, 0, true);
                                  _stage.addEventListener(MouseEvent.MOUSE_UP,on_mouse_up, false, 0, true);
                                  this._mouseX = mouseX;
                                  this._mouseY = mouseY;
                                  //playerShot = new PlayerShot(_xPos,_yPos, _mouseX, _mouseY, _gameModel);
                                  _spriteGridClass1.initTileSheetData();
                                  playerHeadLegsRt = new BlitSprite(_tileSheet, _spriteGridClass1.headLegsRightFrames, 0);
                                  _spriteGridClass1.initTileSheetData();
                                  playerHeadLegsLft = new BlitSprite(_tileSheet, _spriteGridClass1.headLegsLeftFrames, 0);
                                  _spriteGridClass1.initTileSheetData();
                                  playerHoldRot = new BlitSprite(_tileSheet, _spriteGridClass1.holdRotFrames, 0);
                                  _spriteGridClass1.initTileSheetData();
                                  getPistol = new BlitSprite(_tileSheet, _spriteGridClass1.getPistolFrames, 0);
                                  _spriteGridClass1.initTileSheetData();
                                  getMG = new BlitSprite(_tileSheet, _spriteGridClass1.getMGFrames, 0);
                                  _spriteGridClass2.initTileSheetData();
                                  getShot = new BlitSprite(_tileSheet2, _spriteGridClass2.getShotFrames, 0);
                                  _spriteGridClass2.initTileSheetData();
                                  getFT = new BlitSprite(_tileSheet2, _spriteGridClass2.getFtFrames, 0);
                                  //***weapons
                                  _spriteGridClass2.initTileSheetData();
                                  pistolRot = new BlitSprite(_tileSheet2, _spriteGridClass2.pistolRotFrames, 0);
                                  _spriteGridClass2.initTileSheetData();
                                  FTRot = new BlitSprite(_tileSheet2, _spriteGridClass2.ftRotFrames, 0);
                                  _spriteGridClass2.initTileSheetData();
                                  shotRot = new BlitSprite(_tileSheet2, _spriteGridClass2.shotRotFrames, 0);
                                  _spriteGridClass2.initTileSheetData();
                                  MGRot = new BlitSprite(_tileSheet2, _spriteGridClass2.mgRotFrames, 0);
                                  //Pistol left and right frames
                                  _spriteGridClass1.initTileSheetData();
                                  pistolRight = new BlitSprite(_tileSheet, _spriteGridClass1.PistolRightFrames, 0);
                                  _spriteGridClass1.initTileSheetData();
                                  pistolLeft = new BlitSprite(_tileSheet, _spriteGridClass1.PistolLeftFrames, 0);
                                  drawCrosshairs();
                                  //draw();
                        private function keyDownHandler(event:KeyboardEvent):void
                                  if (_gameModel.gameMode != "play") return;
                                  processKeyDown(event);
                        private function keyUpHandler(event:KeyboardEvent):void
                                  if (_gameModel.gameMode != "play") return;
                                  processKeyUp(event);
                        internal function processKeyDown(event:KeyboardEvent):void
                          if(event.keyCode == Keyboard.A || event.keyCode == Keyboard.LEFT)
                                    walk = true;
                            acceleration_X = -aSpeed;
                          if((event.keyCode == Keyboard.D)||
                                   (event.keyCode == Keyboard.RIGHT))
                                    walk = true;
                            acceleration_X = aSpeed;
                          if((event.keyCode == Keyboard.UP)||
                                   (event.keyCode == Keyboard.W))
                           jump=true;
                          if((event.keyCode == Keyboard.DOWN)||
                                   (event.keyCode == Keyboard.S))
                                    //crouch = true;
                          if(event.keyCode == Keyboard.Q)
                                  switchWeapon("minus");
                            dontShowHoldRot = false;
                          if(event.keyCode == Keyboard.E)
                                  switchWeapon("plus");
                                  dontShowHoldRot = false;
                        internal function processKeyUp(event:KeyboardEvent):void
                            if (event.keyCode == Keyboard.LEFT
                            ||event.keyCode == Keyboard.RIGHT||
                         event.keyCode == Keyboard.A
                            ||event.keyCode == Keyboard.D)
                            acceleration_X = 0;
                                   walk = false;
                          if((event.keyCode == Keyboard.UP)||
                                   (event.keyCode == Keyboard.W))
                             jump = false;
                           if((event.keyCode == Keyboard.DOWN)||
                                   (event.keyCode == Keyboard.S))
                             acceleration_Y = 0;
                             //crouch = false;

  • Avoid window getting focus after pressing a mouse button on it

    I want that a window does not get focus although I press a mouse button on it, in Windows XP.
    I have search in Microsoft help and this fact is controlled by the Operating System itself. The notification that is sent after the user presses a mouse button is WM_MOUSEACTIVATE notification. The return value of this notification indicates the behaviour of the window after the mouse down, existing 4 options: MA_ACTIVATE, MA_ACTIVATEANDEAT; MA_NOACTIVATE & MA_NOACTIVATEANDEAT. The default is the first one, but I want to change the behaviour of the window to be the the third one: MA_NOACTIVATE, that does not activate the window, and does not discard the mouse message. The function that performs this is DefWindowProc according to the MSDN Help content.
    Any help about doing this in Labview? Is there any special function in Labview that allows setting this behaviour to a window or should I use a Windows dll? In that case how can be programmed? Has anyone done it before? I'm working with Labview 8.6.1, and I haven't found anything about this. Any help will be very useful.
    Thank you very much in advance.
    David Fernández

    It is the front panel window of a VI which I don't want to get focus. I have tried to achive this with property nodes, but the problem I think that cannot be solved in this way, because is the Operative System that gives the focus to the window when pressing a mouse button before Labview does anything. You can release the focus once the window have taken it with the Front Panel window focus property node, but what I really want is to keep the focus on the old window.
    My idea is that the VI act as a background of my application, so never can be over the rest of the windows. Some of them are floating but others are standard and I don't want to use modal windows, so I cannot solve this with the Window Appearance options.
    I have also tried to discard the mouse down in the Mouse Down? event, but I doesn't work, the window continues getting the focus although does not carry on any action.
    Any suggestion?
    Thank you for your interest
    David F

  • Custom TextInput itemEditor not getting focus.

    I have an AdvancedDataGrid that has a custom itemEditor on an amounts field. If I do an inline textInput itemEditor everything works fine, but if I separate out the textInput itemEditor into it's own component then when I click on the amounts column it doesn't seem to get focus. What happens is I click once and it appears like the text box has appeared, but there is not cursor, so I can't start typing my amount. I need to click a second time in the cell for the cursor to appear.
    Here are my datagrid columns:
    <datagrids:columns>
            <mx:AdvancedDataGridColumn dataField="Customer" headerText="Cust" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="Balance" headerText="Bal" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="paymentAmountString" headerText="Amount"
                               editable="true" textAlign="right"
                               editorDataField="amountText" itemEditor="com.ihcfs.flex.renderers.AdvancedAmountTextInputRenderer">
            </mx:AdvancedDataGridColumn>
        </datagrids:columns>
    Here is my custom renderer/editor, I've tried both a spark TextInput and an mx:TextInput. They both have the same behavior.
    <?xml version="1.0" encoding="utf-8"?>
    <s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                      xmlns:s="library://ns.adobe.com/flex/spark"
                                      xmlns:mx="library://ns.adobe.com/flex/mx"
                                      focusEnabled="true">
        <fx:Script>
            <![CDATA[
                public var amountText:String;
            ]]>
        </fx:Script>
        <s:TextInput id="amountTextInput"
                     width="100%" height="100%"
                     textAlign="right"
                     change="amountText = amountTextInput.text;"
                     focusEnabled="true"
                     editable="true"
                     restrict="[0-9][.]"/>
    </s:MXAdvancedDataGridItemRenderer>
    If I do an inline item editor it works just fine, it's when I move it out to a reusable component that this behavior happens.
    Inline:
    <datagrids:columns>
            <mx:DataGridColumn dataField="customer" headerText="Cust"
                               editable="false" textAlign="center"/>
            <mx:DataGridColumn dataField="balance" headerText="Bal"
                               editable="false" textAlign="center"/>
            <mx:DataGridColumn dataField="paymentAmountString" headerText="Amount"
                               editable="true" editorDataField="text" textAlign="right">
                <mx:itemEditor>
                    <fx:Component>
                        <mx:TextInput width="100%" height="100%" textAlign="right"
                                      focusOut="textinput1_focusOutHandler(event)"
                                      focusIn="textinput1_focusInHandler(event)">
                            <fx:Script>
                                <![CDATA[
                                    import mx.controls.Alert;
                                    import mx.controls.Text;
                                    import mx.events.FlexEvent;
                                    import mx.formatters.CurrencyFormatter;
                                    [Bindable]
                                    private var originalAmount:Number;
                                    private var amountFormatter:CurrencyFormatter = new CurrencyFormatter();
                                    protected function textinput1_focusOutHandler(event:FocusEvent):void
                                        var e:TextEvent = new TextEvent("amountEntered", true);
                                        var textField:TextField = event.target as TextField;
                                        var newAmount:Number = 0;
                                        if(!isNaN(parseFloat(textField.text))){
                                            newAmount = parseFloat(textField.text);
                                        e.text = new String((newAmount - originalAmount) + "");
                                        dispatchEvent(e);
                                    protected function textinput1_focusInHandler(event:FocusEvent):void
                                        var textfield:TextField = event.target as TextField;
                                        if(!isNaN(parseFloat(textfield.text))){
                                            originalAmount = parseFloat(textfield.text);
                                        } else {
                                            originalAmount = 0;
                                ]]>
                            </fx:Script>
                        </mx:TextInput>
                    </fx:Component>
                </mx:itemEditor>
            </mx:DataGridColumn>
        </datagrids:columns>
    Thanks for the help!

    I attempted to do as you said using the following code:
    override public function setFocus():void{
         stage.focus = amountTextInput;
         amountTextInput.setFocus();
    I also tried adding an event handler to my renderer to capture the focus in event and try the same thing:
    <s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                      xmlns:s="library://ns.adobe.com/flex/spark"
                                      xmlns:mx="library://ns.adobe.com/flex/mx"
                                      focusEnabled="true"
                                      focusIn="mxadvanceddatagriditemrenderer1_focusInHandler(event)">
    protected function mxadvanceddatagriditemrenderer1_focusInHandler(event:FocusEvent):void
         amountTextInput.setFocus();
    Neither of these solutions work. I could just go back to using the inline code, but I'd prefer to not copy and paste that code into several different grids.
    Thanks again for the help.

  • In Messages, how can I get the most recent entries to appear on top, like with my emails?  Thanks!

    In Messages, how can I get the most recent entries to appear on top, like with my emails?  Thanks!

    HI,
    A Note.
    Technically the most recent Conversation (or Chat) that has a new message (be it iMessage or IM) will move to the top in the list on the left if it is set in the View  Menu to do so.
    Obviously this does need more than one Conversation or Chat to be listed to work.
    It does not change the focus of the Chat/Conversation you are viewing.
    iChat - the forerunner naver had an option to invert the chats.
    The iChat Feedback page is where I use.
    You will also see it does not list iChat 6 depsite listing Lion.
    In this sense it has always beeen out of step on the iChat/Messages version front  (it took me a long time via the Lounge and Host help to get it on the list of pages to be updated on New OS versions)
    11:00 PM      Friday; June 28, 2013
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.4)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • "Can't move focus" message

    I'm attempting CSH WebHelp from IE7 and getting the following
    error message:
    "Can’t move focus to the control because it is
    invisible, not enabled, or of a type that does not accept the
    focus."
    The mesage goes on to refer to whtdhtml.htm.
    Any suggestions?

    Perhaps worth adding that it works OK in Firefox.

Maybe you are looking for

  • Long "lag" after taking a screenshot.

    I press CommandShift3 to take a screenshot of the entire screen. By default, it goes to my desktop, as it should. The problem though.. Right after pressing the three keys, I hear the camera-shutter sound effect for the screenshot, but after that for

  • Set an array with undeterminate size

    I should know this by now, but go figure. If I want to set up an array of Strings, yet I do not know how many Strings I am going to stick in it, how would I do so? For example, if I want to create an array myArray, and I do not know whether I am goin

  • Combobox and arraycollection

    Hi all, I am totaly new with Flex, and need your help. I have a ArrayCollection getMD that saved the field passed from coldfusion cfc ++++++++++++++++++++++++++++++ <cfcomponent output="false"> <cffunction name="getMD" access="remote" returntype="que

  • Purchased amazon, adobe premier elements 13 & photoshop elements 13 but there is no redemption code

    There was no code on the box or on the disc

  • Session Failover Documentation

    Is there any detailed documentation available concerning the configuration of session failover in the Java EE 5 preview? Michael