Moving a label in a panel using keyboard

Hello,
I have a component in a panel. The panel has got vertical and horizontal scroll bars. I need to move the label using the arrow keys on the key board. It only works for VK_LEFT AND VK_UP and when I try to move the label DOWN or RIGHT, the scroll bars move. I need to hold the CTRL+ARROW KEY to get the functionality.
How do I over come this type of error? i.e I dont want to hold the CTRL key and I want only the arrow keys to do the work.
Thanks

Hi,
Can you please correct this code? I can move the label UP and LEFT but when I move down or right, the scroll pane is moving. Just Click on the label and then try to move the label. Any ideas would help.
Thanks
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MoveLabel extends JFrame
     JLabel label;
     public MoveLabel()
          label = new JLabel(new ImageIcon("copy.gif"));
          label.setBounds(20,30,16,19);
          label.addKeyListener(new KeyAdapter()
               public void keyPressed(KeyEvent ke)
                    if(ke.getKeyCode() == KeyEvent.VK_DOWN)
                         label.setLocation(label.getX(),label.getY()+1);
                         repaint();
                    if(ke.getKeyCode() == KeyEvent.VK_UP)
                         label.setLocation(label.getX(),label.getY()-1);
                         repaint();
                    if(ke.getKeyCode() == KeyEvent.VK_LEFT)
                         label.setLocation(label.getX()-1,label.getY());
                         repaint();
                    if(ke.getKeyCode() == KeyEvent.VK_RIGHT)
                         label.setLocation(label.getX()+1,label.getY());
                         repaint();
          label.addMouseListener(new MouseAdapter()
               public void mouseClicked(MouseEvent me)
                     if(me.getClickCount() == 1)
                          boolean dd = label.isOptimizedDrawingEnabled();
                          boolean ff = label.requestFocusInWindow();
                          repaint();
          JPanel p = new JPanel();
          p.setPreferredSize(new Dimension(2000,1000));
          p.setLayout(null);
          p.add(label);
          JScrollPane js = new JScrollPane(p);
          getContentPane().add(js);
     public static void main(String args[])
          MoveLabel frame = new MoveLabel();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.setSize(300,300);
          frame.setVisible(true);
}

Similar Messages

  • Moving selected objects up and down with keyboard is automaticly applying a colour fill.

    Hi,
    My InDesign is strangely applying a colour fill when i move an objects up or down using the directional arrow in my keyboard. If the colour pallet is open. Nudging an object up makes the pallet disappear on the first press. It then reappears on the second press while filling the object (text frame) with black. This is instensly frustrating. How can I stop this? Suggestions would be very appreciated.
    I have already reset the preferences.
    Cheers,

    Thanks for your reply.
    I fixed the problem by replacing the keyboard!
    Cheers,
    Nick Meadows
    0421 976 704
    www.nickmeadows.com
    Date: Fri, 30 Mar 2012 06:01:22 -0600
    From: [email protected]
    To: [email protected]
    Subject: Moving selected objects up and down with keyboard is automaticly applying a colour fill.
        Re: Moving selected objects up and down with keyboard is automaticly applying a colour fill.
        created by Peter Spier in InDesign - View the full discussion
    I have to ask if you reset the prefs uing one of the methods in this thread: Replace Your Preferences If not, there's a good chance you left out one of the files, so please try again using one of the listed methods. And please tell us the OS and your version of ID, including the patch level. Obviously this is not normal behavior. It sounds as if the Swatches panel has focus when you are pressing the arrow keys.
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4302200#4302200
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4302200#4302200. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in InDesign by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Adding a label on a panel

    i have around 7 buttons. Whenever i click on any 1 button, a label with an ImageIcon parameter needs to be displayed on a panel.
    when the user clicks the second button, another label with an ImageIcon gets added on the same panel(now the panel has first label+ second label).
    These labels can also be moved on the panel using mouse(i have the code to make the label move on the panel).
    How do i add these labels on my panel on their respective button clicks?? thanx in advance

    i have the following code which adds images on panel and also moves them.you can use any of your own images.i do not know how to add the data structure you suggested....so please help me...thanx in advance
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.datatransfer.*;
    import java.io.*;
    public class Post extends JFrame implements ActionListener,MouseListener,MouseMotionListener
         Container con;
         MenuBar mbar;
         Menu file,edit,view;
         JPanel p1;
         JPanel dropZone;
         private int xAdjustment;
         private int yAdjustment;
         Component dragComponent;
         int xpoint;
         int ypoint;
         Uml()
         super("Model Transformation Tool");
         con=getContentPane();
         Toolkit kit = Toolkit.getDefaultToolkit();
             final Clipboard clipboard =kit.getSystemClipboard();
         addMouseListener(this);
         addMouseMotionListener(this);
         ImageIcon act = new ImageIcon("..\\uml\\actor4.gif");
         JButton actor = new JButton(act);
         ImageIcon inher = new ImageIcon("..\\uml\\inher.gif");
         JButton inheritance = new JButton(inher);
         actor.setActionCommand("actor");
         actor.addActionListener(this);
         inheritance.setActionCommand("inheritance");
         inheritance.addActionListener(this);
         dropZone = new JPanel();
             dropZone.setBorder(BorderFactory.createLineBorder (Color.blue, 2));
               dropZone.setBackground(Color.WHITE);
         p1=new JPanel();
         con.setLayout(new BorderLayout());
         p1.setLayout(new FlowLayout());
         p1.add(actor);
         p1.add(inheritance);
         con.add(p1,BorderLayout.NORTH);
         con.add(dropZone, BorderLayout.CENTER);
         setVisible(true);
         public void actionPerformed(ActionEvent e)
              String tmp=e.getActionCommand();
              if("actor".equals(tmp))
              Icon icon1 = new ImageIcon("..\\uml\\actorfull.gif");
              JLabel label1=new JLabel(icon1);
              dropZone.add(label1);
              dropZone.revalidate();
              String aname=JOptionPane.showInputDialog("Enter the name of actor");
              JLabel actorname=new JLabel(aname);
              dropZone.add(actorname);
              dropZone.revalidate();
              if("inheritance".equals(tmp))
              Icon icon3 = new ImageIcon("..\\uml\\inher_full.gif");
              JLabel label3=new JLabel(icon3);
              dropZone.add(label3);
              dropZone.revalidate();                    
    }//actionPerformed
         public void mousePressed(MouseEvent e)
              Container container =  (Container)e.getSource();
              Component component =  container.findComponentAt(e.getX(), e.getY());
              if (component instanceof JPanel) return;
              dragComponent = component;
              xAdjustment = dragComponent.getLocation().x - e.getX();
              yAdjustment = dragComponent.getLocation().y - e.getY();
         **  Move the component around the panel
         public void mouseDragged(MouseEvent e)
              if (dragComponent == null) return;
              dragComponent.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
         **  Deselect the component
         public void mouseReleased(MouseEvent e)
              dragComponent = null;
         public void mouseClicked(MouseEvent e) {}
         public void mouseMoved(MouseEvent e) {}
         public void mouseEntered(MouseEvent e) {}
         public void mouseExited(MouseEvent e) {}
         public static void main(String args[])
         Toolkit kit = Toolkit.getDefaultToolkit();
         Dimension screenSize = kit.getScreenSize();
         int screenWidth = screenSize.width;
         int screenHeight = screenSize.height;
         Uml obj=new Uml();     
         obj.setBounds(0, 0, screenWidth, screenHeight-29);
         obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }//class

  • Why is it so hard to just use Keyboard controls to navigate Finder?

    In pre OS X days I and my co-workers would use only keyboard shortcuts to navigate file servers faster than the network could even refresh the display just using Command keys and Tab and letters…
    In Finder if I want to move to the shortcuts side-bar (the way you can in an Open dialogue box with Tab) it seems to require cursor action, and since I use a tablet that means moving RH away from keyboard and gripping pen, which we all seem to hold between thumb and palm.
    If I hit Tab with a Finder window active, I get the current directory of files and I can manually move thorugh Cmd-Sft-D for desktop and then drill down etc etc  I also find it can be really hard to make a window or floating pallete the active window, and even when it is, impossible to highlight the correct field/content just using Keyboard shortcuts. I'm finding hard to beleive I not missing something, this being Apples OS and Apple have had unviersal access for a few decades!

    Hmmm, if these are commonly used Folders, try dagging them to the right side of the Dock between Applications & trash.

  • Labels in my Panel

    I'm sorry that I couldn't figure this out from the search. I tried a few things but none seemed to work.
    I have a panel that contains labels. The labels represent objects alive in my system. The Frame watches these objects and updates every second.
    I start the panel empty except for a static label at the top that says "objects".
    in each loop, I collect object names in an array and create labels for each. I want to replace the current panel content with the new labels. I have tried re instantiating the panel, re writing the panel's paint method to add new labels, but my panel remains looking the same. Can anyone help?
    Thanks

    Using awt Panels. I didn't want later users to have to have a higher version of java. I'm not married to the version though. Below is the code that I am using...
      // Creates the userDisplay panel
      // UserDisplay is defined in the Frame
        public void createUserDisplay(ArrayList users){
          users = users==null?new ArrayList():users;
          if(userDisplay != null){
            userDisplay.removeAll();
          }else{
            userDisplay = new Panel();
          int labelHeight = 8;
          int labelWidth = 24;
          userDisplay.setSize(labelWidth,0);
          userDisplay.setBackground(Color.white);
          userDisplay.setLayout(new java.awt.GridLayout(0,1));
          Label usersHeader = new Label();
          usersHeader.setSize(labelWidth,labelHeight);
          usersHeader.setBackground(Color.white);
          usersHeader.setFont(BIG);
          usersHeader.setText("USERS");
          usersHeader.setBounds(0,labelWidth,labelHeight,labelWidth);
          userDisplay.add(usersHeader);
          for(int a = 0; a < users.size(); a++){
            Label L = new Label();
            L.setFont(normal);
            L.setBounds(0,labelWidth + (a * labelHeight),labelHeight,labelWidth);
            L.setBackground(
              ((SimpleChat.User)users.get(a)).status == 1
              Color.yellow
              Color.white
            L.setSize(labelWidth,labelHeight);
            L.setText(((SimpleChat.User)users.get(a)).name);
            userDisplay.add(L);
            System.out.println("Added " + L.getText());
          }

  • Delayed response of when moving objects in diagram and panel, happend in LV 6, only for vi's compiled from previous versions. any suggestions?

    When I using the mouse to select portion of the diagram or the panel, or when I moving objects- I found that in all the vi's that I compiled from former versions of labview- there is a delay of close to a second to the actual selection or movement of the item. This happens in 2 machines out of 5 that I tested it, and it happened both in windows 2000 and in windows 98. any suggestions?

    Sometimes a video driver issue. Update your video driver.
    Or turn down the video driver hardware acceleration. Right-click an
    empty area of the desktop, choose the Settings tab, choose the Advanced
    button.
    The location of this differs in different versions of Windows.
    Win2000: go to Troubleshooting, and turn down the slider for hardware
    acceleration.
    Win98: I think it's on another tab.
    Mark
    ilan wrote:
    >
    > Delayed response of when moving objects in diagram and panel, happend
    > in LV 6, only for vi's compiled from previous versions. any
    > suggestions?
    >
    > When I using the mouse to select portion of the diagram or the panel,
    > or when I moving objects- I found that in all the vi's that I compiled
    > from former versions of labview- there is a delay
    of close to a second
    > to the actual selection or movement of the item. This happens in 2
    > machines out of 5 that I tested it, and it happened both in windows
    > 2000 and in windows 98. any suggestions?

  • Movieclip.x movement using keyboard event

    Hi, im working on a game project and i have a question about movie clip movement using keyboard event.
    Basicly i have a character on screen and it can move on the x axis using the left and right buttons.
    Im making my charater move by changing the x value of the character movieclip but i find very it laggy and not smooth and if im going point by point
    then it's too slow.
    Whats the best way to make the character move so that the transition will be smooth.

    Ok obviously you've left out where you add your eventListener, i'll assume that's a KEY_DOWN event. When the user holds down a key, that key event is triggered once immediately and then after a pause it is triggered at regular intervals. Check this out by holding down the up/down arrow and watching this browser window scroll.
    That's not the movement you'd be looking for when moving a character in a game. Instead, you'd be setting a variable on KEY_DOWN to indicate the character direction - it could be an integer for example that you increase by 1 if the user pressed RIGHT or decrease by 1 if the user pressed LEFT.
    In addition to your KEY_DOWN eventListener, you could have an ENTER_FRAME and  KEY_UP eventListeners set up:
    The enterFrame event handler could move the character in the direction specified in your direction variable. This is where you might ensure your character doesn't go beyond its limits in both directions.
    In the keyUp event handler, you could do the converse of what you did in the keyDown handler(increase by 1 if the user released LEFT, decrease by 1 if the user released RIGHT).

  • Find a component with his id ? (ex find a Label in a Panel with the Label's id)

    Hello, I need to find a children component with his id (so without getchildat ou byname methods)
    ex :
    <mx:Panel id="panel1" x="10" y="10" title="PANEL 1" width="400" height="300">     
    <mx:Label id="label1" x="15" y="15" text="label 1 dans panel 1" />
    <mx:Panel id="panel2" x="70" y="50" title="panel 2 ds panel 1" width="100" height="50">
    <mx:Label id="label2" x="25" y="25" text="label 2 dans panel 2" />                    
    </mx:Panel>                    
    </mx:Panel>
    with id=label2 or id=panel2 I would like have the Label or Panel, without having to look in children of children
    because there is only one single id in application I think it's possible, but don't find how
    think's in advance for your ideas !
    Dave

    hello atta707, think you for you help !
    but I need it to find components I create with my methods createLabel and createPanel
    > I have found this[id]
    it work good for components who are first in application
    but it doesn't find components who are created after
    for example, with :
    <mx:Panel id="firstpanel"></mx:Panel>
    this[firstpanel] work
    but if I create a new panel in the first panel :
    newPanel = new Panel();
    this[firstpanel].addChild(newPanel)
    this[idNewPanel] doesn't work !
    so it seems when you use addChild it add the component in screen and children tree
    BUT not in this[id]
    and if I try
    this[idNewPanel]=newPanel it doesn't work
    so I need a method to find NEW components by their id
    or to oblige this[id] to register the new components created
    any idea ? >

  • Using Keyboard keys in Fields setting in Crystal Report Design ?

    Hi Experts
    I want to know that how can I change text object or a field size or position by keyboard. sometimes it works and sometimes not. What is the setting for using keyboard.
    Thanks
    Regards
    Gorge

    Keyboard keys will only work under certain modes in CR.  You have to check the mode constantly to see in which ways they work.  There are too many conditions may cause them not work.  That list could be too long to find them all.  You would have a good grasp on the rule after you familiar with them.
    Thanks,
    Gordon

  • My keyboard on macbook pro (laptop) is acting weird. One key is not responding at all. Have verified using Keyboard viewer and some other keys are printing the unresponsive character at random.

    my keyboard on macbook pro (laptop) is acting weird. One key is not responding at all. Have verified using Keyboard viewer and some other keys are printing the unresponsive character at random. "z" is the unresponsive character.
    Is it a damaged keyboard ?
    The laptop is just 2 months old, will Apple replace it with a new one if its indeed a damaged keyboard or just repair, I use it for official purposes so being without a laptop is not much of an option.

    No one here works for Apple, so we don't know what Apple might or might not do.  If it's a genuine defect, they will of course repair it under warranty.  It is not their responsibility if it effects your ability to work or not, so that's on you.
    If, however, they determine that the key is problematic as a result of your misuse of the laptop, then everything is on you.  And trust me, if they find a glob of dried up beer or coffee there, they will charge you.
    Your only choice is to take it in for repair.

  • I am Unable to Type or use Keyboard in Firefox 18.0 anywhere including URL bar and Search Bar. how should rectify this?

    I am unable to type anything or use keyboard to type in Firefox. I am using Firefox 18.0 installed on Windows 7.
    I am able to Paste into the URL bar and also the Search bar but absolutely not able to type in it.
    I have already tried the "reset" option but still unable to type.
    Also tried Firefox in safe mode with disabled addons but still unable to type.
    Installed a fresh copy of firefox after uninstalling Firefox and deleting the old folder "Mozilla Firefox" from windows. but still unable to type.
    Please tell me a solution to this.

    I'm not on a laptop so I don't have a FN key. But on my desktop F9 + Windows key appears to have resolved the issue for me. Thanks for the help!

  • The CC control panel use to show my 4 applications CC, CS6, LR5 and Bridge, now LR5 is no longer showing up. I pay for the photographer bundle, which includes LR5 and CC, why has it been dropped off? Is there any way to bring it back in the panel, because

    The CC control panel use to show my 4 applications CC, CS6, LR5 and Bridge, now LR5 is no longer showing up. I pay for the photographer bundle, which includes LR5 and CC, why has it been dropped off? Is there any way to bring it back in the panel, because in the listed applications which can be added below it is not listed.  Thanks!

    If you're a paying Creative Cloud member, you may not see Lightroom in the Creative Cloud if your computer doesn't meet the minimum system requirements. Check to make sure that your system meets the minimum requirements for the latest release of Lightroom.
    If you're using a trial version of Creative Cloud, the Lightroom trial is not available through Creative Cloud. It is, however, available as a stand-alone trial. See Install Lightroom trial | Creative Cloud membership. 
    Please refer to : Lightroom and Creative Cloud FAQ
    Regards
    Rajshree

  • I have a Mac Pro 4,1 quad core intel Xeon running mac OSX 10.6.8 and I have just moved studios and now need to use the Internet wirelessly but there's no airport facilities on this model can anyone tell me what model of airport card I would need for this

    I have a Mac Pro 4,1 quad core intel Xeon running mac OSX 10.6.8 and I have just moved studios and now need to use the Internet wirelessly but there's no airport facilities on this model can anyone tell me what model of airport card I would need for this mac

    Instead of getting a wireless card for the Mac Pro, you might want to consider getting an 802.11ac wireless bridge device that would enable you to connect more than one device to it by Ethernet cable and to eventually take advantage of the faster 802.11ac wireless standard.

  • Change BG color of Panel using script (AS3)

    Dear, all
    I am a newbies in Flex. Now I have some trouble with thw
    sample thing.
    That is how can I change BackgroungColor of panel using
    script(AS3)
    I can do it by mxml BUT!! I really need to change it using
    AS3. Does you know what should I do NEXT.

    When you lookup a component in FB3 help sys, if you see it
    under styles, then you need to use setStyle() in AS, if you see it
    as a property, just use dot notation.

  • Page up and down without using keyboard

    can any body tell me, how can I write the code for page up and page down in alv grid report without using keyboard.I have make a report(showing in alv grid formate) and I am using menu printer(se41) and gave P,P+,P-,P-- in function key.
    and call this function in report using pf-status. but i didnot get the result without keyboard.while using keyboard page up and page down it is working fine.

    Hi Rakesh,
                    This is the code for ur problem check it once.We have to use this code according to ur requirement ok..The compulsory condition is data is present in the internal table not in database table.If it is in database table move it to internal table first.And follow the below logic that will work fine 4 ur problem check it once.
    *Local Variables
      DATA: lv_temp  LIKE sy-tabix.
    CASE sy-ucomm.
    *Fetch the FIRST Line from the Internal Table.
        WHEN 'FIRS'.
          READ TABLE gt_data INTO wa INDEX 1.
          lv_temp = sy-tabix.
    *Fetch the NEXT Line from the Internal Table.
        WHEN 'NEXT'.
          lv_temp = lv_temp + 1.
          READ TABLE gt_data INTO wa INDEX lv_temp.
    *Fetch the PREVIOUS Line from the Internal Table.
        WHEN 'PREV'.
          lv_temp = lv_temp - 1.
          READ TABLE gt_data INTO wa INDEX lv_temp.
    *Fetch the LAST Line from the Internal Table.
        WHEN 'LAST'.
          READ TABLE gt_data INTO wa INDEX sy-tfill.
          lv_temp = sy-tfill.
    Award points if helpful.
    Kiran Kumar.G.A
                     Have a Nice Day..

Maybe you are looking for

  • Camera no longer working on iPad air

    Hi everyone I switched my ipad air on and for some reason the camera doesn't appear to be working ? When i open the camera app there is just a black screen. It allows me to swipe from video to photo, but nothing happens and i cannot press the picture

  • Smartdisk Firelight 80g external hard drive won't mount

    I have an old Smartdisk Firelight 80g external hard drive.  I haven't used it in a couple years.  When I plug it in I get the error "The disk you inserted was not readable by this computer" It is connected to my MacBook Pro running 10.7.5 through a f

  • How do I remove spy software from my iPhone 4?

    I believe that I have spy software on my phone. From what I have seen advertised online phone calls, numbers, SMS/MMS and email can all be monitored.  The iPhone 4 is one of the smart phones listed on these various sites.  How can I find out if this

  • No sound during record with soundblaster for Vi

    I have Windows Vista and am using Audigy Advanced MB Sound Blaster Wave Studio to record music from a multi-track recording source. Wave Studio records it just fine and will play it back well, but I can't hear the music while I'm recording it, which

  • [cs5 - JS] How to get UID

    Hello, is there any way to get UID of selected pageItem? I can get selected item/items thats no problem, but I cant get the UID of selected item. Thank you