dear all,

I have made one program, but i am stuck with one problem.
I have taken one scrollpane in simple desktop GUI application in java.

My hierarchy of Scroll pane is as below.

JFrame
|_JTabeedPane
  |_JScrollPane
    |_JPanelMain
      |_Jpanel
        |_JPanelA
        |_JPanelB

Now all the components are in JPanelA and JPanelB.
So when i press TAB,it traverse through all textboxes, but problem is it is not automatically scrolls down.
TAB is working perfectly, so when i press TAB it goes to text box one by one,but it doesn't display the element outside the screen area.
So it will not auomatically scoll down.
I am using Netbeans 7.2 and also i have set property of the Scrollpane i.e. Auto Scroll=true.
But still it's not working.

Please tell me what to do now.Or which property i have to explicitly call on this scroll pane.

Thank you.

Container panel = myTextField.getParent();

SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        panel.scrollRectToVisible(myTextField.getBounds());
    }
});
  • or another way by determine Rectangle from some Point of JPanel and by moving with the JViewport (not easiest of ways, but you can to e.i. centering Point rellative to the JViewport)

i also have done above things,but still its not working.
Is there any other probable way to fix it up?

I want to scroll down my page when i press TAB button from keyboard and when the focus gone on textbox which is not in screensize, it automatically drags down for showing the contents.

Thanks a lot...

  • add KeyBindings to Top-Level Container and override TAB key

  • remove KeyBindings for TAB Key (built_in KeyBindigs in API) from all JComponent ( e.g. JTable, JList, JTextComponents) to avoid firing duplicate events from / to JComponents hierarchy and avoiding to jumping of JComponents on the screen

  • if you remove TAB betweens JComponents then you can to broke TAB Key as command for next focusable JComponent, and switch to the any JComponent could be possible by MouseEvents only, don't confuse the users, I'd suggest don't do that

  • I'd be use JButton for that or better onw key_shotcut e.g. ALT (CTRL) + Whatever rather than quite frequently used TAB Key, up to you

mKorbel:

At which level i have to put that thread, means at which event....
please tell me.

Thank you.

This article has been dead for over six months. Start a new discussion instead.