How to have focus in 2 JPanels on 1 JFrame?

Hey all..
Like i wrote in the subject, how can i do that?
I have 2 JPanels in 1 JFrame. 1 top JPanel and 1 buttom JPanel. I've a keylistener in top JPanel and a buttonslistener in buttom JPanel. When i press on the button on the buttom JPanel, then my keylistener wont trigger in the top JPanel.
Plz help.
Thx.

The whole point to window focus is to avoid this! There is at most one focused component per window.
As a rule of thumb, when someone uses a KeyListener, they're mistaken. You should be using key binding. This can make your focus problems go away, since you can choose to associate the keyStoke with the whole window, not just the focused component.
[http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]

Similar Messages

  • How to associate Flex Dockbar to JPanel instead of JFrame

    Hello
    I have got JAVA 1.6 application consists of main frame with two parts as left JTree and central main JPanel. On base sselected item on the left tree i switch panels on central main panel. These panels which are shown on central panel consist of windows that I need to make as dockable(Flexdock framework). I've found some examples but all work with JFrame as main container. When I use it for JPanel the relevant dockbar was displayed withing my JFrame componennt and not JPanel.
    Can somebody help me how to do it with this framework?

    First of all, to enable scrolling you should add your Panel into a JScrollPane:
    jPanel1 = new LinesRectsOvalsJPanel();
    JScrollPane jscroll = new JScrollPane(jPanel1);
    PathwayViewer.getContentPane().add(jscroll );Since your Panel has no size, and no components on it, it will assume the panel is of size (0,0). To prevent this from happening, you need to override the getPreferredSize() method of the LinesRectsOvalsJPanel... add following to the LinesRectsOvalsJPanel class...
    private Dimension bckground = new Dimension(img.getIconWidth(), img.getIconHeight());
    public Dimension getPreferredSize() {
            Dimension dim = super.getPreferredSize();
            return new Dimension(Math.max(dim.width, bckground.width), Math.max(dim.height, bckground.height));
    }This means you need to get
    "ImageIcon img = new ImageIcon(FileLocation);" out of the paintComponent method (what you need to do anyway !!! every time your component is painted, the image is recreated !!!)
    You might achieve the same if you override the getMinimumSize() method... (The size of the panel minimum needs to be the size of the bckground, no matter what components are on it...)
    Hope it helps

  • How can i change an existing JPanel from a JFrame after an event happens?

    Good day!
    i'm new in java programing and im trying to build a GUI for a for a small inventory system.
    here's a part of my code............
    if(e.getSource()==invButton){
                   if(username.equals(storekeeper)){
                        cont.add(new Equipment(cont,deck,username),"equipment");
                        deck.show(cont,"equipment");
                        cont.remove(this);
                   }else{
                        cont.add(new EquipmentEmployee(cont,deck,username),"equipmentEmployee");
                        deck.show(cont,"equipmentEmployee");
                        cont.remove(this);
    my code calls a new class called Equipment.java after a button is pressed and add it into a frame.
    but the problem is nothings happened. my code didn't work.
    can anyone help me fix my problem?..
    thanx!!...

    my code calls a new class called Equipment.java after a button is pressed and add it into a frame.
    but the problem is nothings happened. my code didn't work.Did you add the action listener to your button? Like below:
    invButton.addActionListener(this);

  • How to listen for key press when air app does not have focus

    Hi,
    I am developing a application in air and part of the functionality I need is the ability for the app to listen for when a specific key is pressed, even when the air app does not have focus.
    Is there support for this for windows or mac? If not, how might this be accomplished? ANE?    

    Ok Mr. Smartass...Ok
    I'm building a browser that is always open, and when
    a user presses Ctrl+F1 (notice, just those two keys,
    I don't care what else they press...) the browser
    will open up. That way, you don't have to wait for it
    to load all the time.You have two ideas here. One is having a universal key map that always gets ctrl-f1 sent to your app. The other is a program that is constantly running so that you don't have to wait for it to open up. The former is not possible (and this is a good thing) As warneria and I have been saying, it is bad design for an app to try to force an OS to implement this kind of feature.
    If you're not going to help please don't post at all;
    it's a waste of time for both you, me, and anyone
    else who may need help on the same subject. Why wouldBelieve it or not, I am helping you.
    See
    http://www.google.com/search?hl=en&lr=&q=programming+code+side+effects
    and
    http://www.faqs.org/docs/artu/ch04s02.html
    "Doug McIlroy's advice to �Do one thing well� is usually interpreted as being about simplicity. But it's also, implicitly and at least as importantly, about orthogonality."
    anyone in their right mind who's trying to steal
    people's passwords come out and say, "I'm not trying
    to steal people's passwords!"wait, your question is why would someone trying to steal passwords say I'm not trying to steal passwords? I think duplicitous people in their right minds might try to trick you that way.
    Beyond that, even if you're not a malicious hacker - and I am sure you are not - if someone posts a solution to your problem, malicious coders then will have learned how to do it. If you think you're programming or using these forums in a bubble, you are not.

  • How to set Tab ordering in JPanel

    hi all
    i add a JPanel on a JFrame and Various swing Controls on that JPanel. now i want to change tab ordering of components present in my JPanel.
    please guide me how can i do this. i have tried setFocusTraversalPolicy but it does not work with JPanel.

    You should read the article from Sun:
    "How to Use the Focus Subsystem"
    http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
    Moshe

  • How to set focus on opened new JFrame??

    Hi,
    I have a problem:
    I have my active JFrame that I am currently running.
    When I press a JButton I have an action that it opens another JFrame,
    which is minimized (maybe it doesn't have a focus enabled or something)
    How to make the opening JFrame window maximized and make it be the one on the foreground (put the first JRame in background)
    Thanks

    Try this:
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    public class JFrames extends JFrame{
         public JFrames(){
              super();
              // exit on close
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // button to create new JFrame
              JButton button = new JButton("New Frame");
              button.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                        // create new instance and maximize it
                        JFrames frame = new JFrames();
                        frame.setExtendedState(frame2.getExtendedState()|frame2.MAXIMIZED_BOTH);
              // panel to add the button to
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(300, 200));
              panel.add(button);
              this.getContentPane().add(panel);
    // display the frame
    this.pack();
    this.setVisible(true);
         public static void main(String args[]){
              JFrames frames = new JFrames();
    }

  • How to set focus on the last row of JTextPane

    how to set focus on the last row of JTextPane?
    import javax.swing.*;
    import javax.swing.text.html.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MyGUITest extends JPanel implements ActionListener
    {   public static void main(String[] args)
        {   SwingUtilities.invokeLater(new Runnable()
             {   public void run()
              {    JFrame f = new JFrame("My GUI");
                  MyGUITest GUI = new MyGUITest();
                  GUI.setOpaque(true);
                  f.setContentPane(GUI);
                  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  f.pack();
                  f.setLocationRelativeTo(null);
                  f.setVisible(true);
        JTextPane txtP;
        JButton add;
        HTMLEditorKit hek;
        HTMLDocument hd;
        String txt;
        MyGUITest()
        {     this.setLayout(new BorderLayout());
         this.setPreferredSize(new Dimension(400,200));
         txtP = new JTextPane();
         txtP.setEditable(false);
         txtP.setContentType("text/html");
         txtP.setText("");
         hek = new HTMLEditorKit();
         txtP.setEditorKit(hek);
         hd = new HTMLDocument();
         txtP.setDocument(hd);
         JScrollPane sTxtA = new JScrollPane(txtP);
         add = new JButton("add");
         add.addActionListener(this);
         sTxtA.setBorder(BorderFactory.createTitledBorder(""));
         this.add(sTxtA, BorderLayout.CENTER);
         add(add, BorderLayout.SOUTH);
         new Thread(new Runnable()
         {   public void run()
             {   while(true)
              {   try
                  {     Thread.sleep(100);
                  }catch(InterruptedException ex)
                  {     ex.printStackTrace();
                  appendText("This is <b>HTML</b> text");
                  //add.doClick();
         }).start();
        public void actionPerformed(ActionEvent e)
        {     txt = "<b>asd</b>";
         try
         {   hek.insertHTML(hd, hd.getLength(), txt, 0, 0, null);
         }catch(Exception ex){   ex.printStackTrace();   }
        public void appendText(String txt)
        {     try
         {   hek.insertHTML(hd, hd.getLength(), txt, 0, 0, null);
         }catch(Exception ex){   ex.printStackTrace();   }
    }thanks~

    anIdiot wrote:
    im not sure what is the caret location...So don't youthink you should have looked for it in the API?
    anyway, i want the scroll bar to scrolled down automatically when the output is displayed.
    normally, the scroll bar is scrolled down automatically when a new text is inserted, but it doesnt work on this timeGo through camockr's http://tips4java.wordpress.com/2008/10/22/text-area-scrolling/
    db

  • How do I add multiple JPanels to a JFrame?

    I've been trying to do my own little side project to just make something for me and my friends. However, I can't get multiple JPanels to display in one JFrame. If I add more than one JPanel, nothing shows up in the frame. I've tried with SpringLayout, FlowLayout, GridBagLayout, and whatever the default layout for JFrames is. Here is the code that's important:
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import javax.swing.*;
    public class CharSheetMain {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              CharSheetFrame frame=new CharSheetFrame();
              abilityPanel aPanel=new abilityPanel();
              descripPanel dPanel=new descripPanel();
              frame.setLayout(new FlowLayout());
              abilityScore st=new abilityScore();
              abilityScore de=new abilityScore();
              abilityScore co=new abilityScore();
              abilityScore in=new abilityScore();
              abilityScore wi=new abilityScore();
              abilityScore ch=new abilityScore();
              frame.add(aPanel);
              frame.add(dPanel);
              frame.validate();
              frame.repaint();
              frame.pack();
              frame.setVisible(true);
    }aPanel and dPanel both extend JPanel. frame extends JFrame. I can get either aPanel or dPanel to show up, but not both at the same time. Can someone tell me what I'm doing wrong?

    In the future, Swing related questions should be posted in the Swing forum.
    You need to read up on [How to Use Layout Managers|http://download.oracle.com/javase/tutorial/uiswing/layout/index.html]. The tutorial has working example of how to use each layout manager.
    By default the content pane of the frame uses a BorderLayout.
    For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org], that demonstrates the incorrect behaviour.
    The code you posted in NOT a SSCCE, since we don't have access to any of your custom classes. To do simple tests of adding a panel to frame then just create a panel, give it a preferred size and give each panel a different background color so you can see how it works with your choosen layout manager.

  • How to retain focus in Web forms 6i item when displaying pdf image

    How to retain focus in Web forms 6i item when displaying pdf image in a multi-record block?
    Hello.
    I have a Web Forms 6i program (version Forms 6.0.8.19.2) running in a 3-tier application. The web form program has a multi-record block containing invoices. When navigating to a record, the form should display the PDF invoice image which is stored in an Oracle 8.1.7 database as a BLOB in another window. When user press down-arrow, the next PDF invoice image should be displayed.
    I am able to accomplish the functionality above by using web.show_document('URL', target') in the when-new-record-instance. The URL being called is a PL/SQL Web Toolkit stored procedure using wpg_docload.download_file built-in.
    The problem is that the focus is lost on the Webform and the focus is shifted to the PDF image window when you navigate to the next record using down-arrow. I want to retain the focus in the form as this is a data-entry form, the operator will use down-arrow to go to the next-record rather than the mouse. I also only want to do this for this Invoice Entry form and NOT to all forms.
    Please advise how to resolve this problem. Thank you.
    Regards,
    Armando

    Magesh,
    the issue of a SSO protected form showing the logon dialog is a knwon issue for Windows200 and the Oracle9iAS base release. If you applied Forms Patch 1 then this should be solved. Hope that I am right in that you are using Oracle9iAS and not Oracle9iDS. Do you see the Single Sign-On logon screen or the Forms logon dialog directly? Check the forms90.conf file in teh forms90/server directory as this contains the Form sso settings (mod_osso) which by default is commented out and therefore inactive. You need to remove the commenting '#' characters and make sure that each sentence having a '#' in front, after that starts on a new line.
    The Forms deployment documentation within the Oracle9iAS docu provides this information too.
    Frank

  • How to set focus order of multiple Component in a Frame

    I have created a Frame with contain some Label, Textfield, Choice and Buttons
    How do set focus order on these Components

    write an implementation of
    import java.awt.*;
    public class PanelFocusTraversalPolicy extends FocusTraversalPolicy
        public Component getComponentAfter(Container container, Component component)
            if(component.equals(cmp1))
                return cmp2;
            if(component.equals(cmp2))
                return cmp3;
            return cmp1;
        public Component getComponentBefore(Container container, Component component)
            //implentation of method
        public Component getDefaultComponent(Container container)
          return cmp1;
        public Component getLastComponent(Container container)
            return cmp3;
        public Component getFirstComponent(Container container)
           return cmp1;
        public PanelFocusTraversalPolicy()
    }and set the focus traversal of frame.
    setFocusTraversalPolicy(new PanelFocusTraversalPolicy())

  • How to set focus on a Component?

    I'm doing a simple DATA ENTRY program. My web apps contains the ff:
    - 4- buttons (add, save, undo, del)
    - table
    To avoid mistakes on the data entry by a user. I make it a point to limit possible areas of risk. Like:
    ie: when addButton is clicked.
    - we set addButton.setDISABLED(true)
    - also we set delButton.setDISABLED(true)
    Problem: On the web browser, we get an error that saysn "Can't move to the focus control ... blah, blah blah"
    How do I set the focus on other control?

    I suppose this is a javascript error.
    If you are using firefox, could you please add what the error is that you are seeing.
    How are you trying to set the focus on the other button?
    You could try adding javascript code to onclick functionality of the button you are disabling.
    something like:
    onclick = "<client id of the button to have focus>.focus()";

  • How to set focus on UI Element

    Hi All,
    I am using the below code to set the focus on the first row of the table given in the link  [How to set focus at UI element ? ] on enter of an event.
    data: lr_elem type ref to if_wd_view_element.
    lr_elem = view->get_element( <ID of the Link to Action field>).
    if lr_elem is bound.
    view->request_focus_on_view_elem( lr_elem ).
    endif.
    I am getting "Cannot use NULL reference as object error at view".
    Can you please tell me how to get the reference of the "view".
    Thanks
    Praveen

    >
    praveenkumar_81 wrote:
    > Hi All,
    >
    > I am using the below code to set the focus on the first row of the table given in the link  [How to set focus at UI element ? ] on enter of an event.
    >
    >
    data: lr_elem type ref to if_wd_view_element.
    > lr_elem = view->get_element( <ID of the Link to Action field>).
    >
    > if lr_elem is bound.
    > view->request_focus_on_view_elem( lr_elem ).
    > endif.
    >
    > I am getting "Cannot use NULL reference as object error at view".
    >
    > Can you please tell me how to get the reference of the "view".
    >
    > Thanks
    > Praveen
    Hallo Praveen,
    have you controlled that id of the Linktoaction ? there you made error.
    See it in the ViewElement designer .
    should be something like this
    lr_elem = view->get_element( 'LTA_name ' ).

  • How to have "new folder" command automatically select "untitled folder"?

    How to have "new folder" command highlight name change?
    On a couple of my Macs, when I give a "new folder" command, the "untitled folder" name is immediately selected/highlighted for immediate entry of the new name for the folder.
    On other Macs I have, when I give a "new folder" command, I must then manually select the "untitled folder" name before I can type in the new name.
    Does anyone know how to set my Finder so that when I give a "new folder" command it will be immediately highlighted/selected for entry of the new name?
    I'm using the latest OS-X on all of my Macs.

    ZDHart wrote:
    How to have "new folder" command highlight name change?
    On a couple of my Macs, when I give a "new folder" command, the "untitled folder" name is immediately selected/highlighted for immediate entry of the new name for the folder.
    On other Macs I have, when I give a "new folder" command, I must then manually select the "untitled folder" name before I can type in the new name.
    Does anyone know how to set my Finder so that when I give a "new folder" command it will be immediately highlighted/selected for entry of the new name?
    I'm using the latest OS-X on all of my Macs.
    Welcome to Apple Discussions:
    All my Macs select the name in the untitled folder for immediate renaming.
    Exactly what happens when your Mac does not allow immediate renaming? The only way this happens is if the folder loses focus, which can happen if another app is running and takes focus, or if you click the mouse somewhere.

  • I am working in Adobe Acrobat 9 Pro and just created a pdf form from a MS Word document. I need to find out how to have a date field in my form which will update automatically. Can some one out there help me?

    I am working in Adobe Acrobat 9 Pro and just created a pdf form from a MS Word document. I need to find out how to have a date field in my form which will update automatically.

    Update automatically under which circumstances, exactly?

  • How to have a live feed from application server log file (realtime viewr )

    how to have a live feed from application server log file (realtime viewr for apps log files)
    hi , thank you for reading my post.
    is there any way to have a live feed of Application server log ?
    for example is there any application that can watch the log file and show the changes as new log items come in ?
    can some one with more experience help ?

    Your question would be more suited to the Developer Forums
    http://devforums.apple.com
    but anyway...
    My goal is to develop a web application that is able to run on iPhone too, to capture the audio and video content from its camera and mic.
    Web Apps running in Safari don't have access to the camera or mic hardware.
    Or I should built a native application distributed through Apple store?
    That is your only option, although such a system already exists:
    http://itunes.apple.com/us/app/ustream-live-broadcaster/id319362690?mt=8

Maybe you are looking for