Hi,

I have a split container in my frame where the right container has a Jtable and left is filled with different collapse panels displaying detailed data from different parts of the table.

If the user clicks on a column then a collapse panel expands and display the information

If all the collapse panels are expanded then the user should scroll to see information.

Is there a way where the user clicks a column in the table and focus automatically shifts to it's repective panel from the current?

for example if I'm now in the viewing information in the first collapse panel and user clicks a column which refers to the collapse panel which at the end, then the program automatically should directly go (scroll down) to that panel so the focus should be shifted to the panel which is at the end.

I hope I did confuse you.

Basically I would like to know how to shift the focus from one component to other dynamically.

thanks in advance

I thought so. somehow, the focus is shifting but it panel doesn't scroll to the focussed component. Is there any other way?

Not as far as I know. You'll have to set the value of the y ScrollBar in your program to the y position of the component that you just requested focus for, or call scrollRectToVisible on the panel that contains the focus object, passing the focus object's getBounds as the rect. (But maybe someone else knows a better way?)

ps: IMHO scrolling controls on and off the screen makes for a confusing UI. Personally I would reserve scrolling for documents that are genuinely too big, and use something like a JTabbedPane for controls.

  • myPanel.scrollRectToVisible(JComponentFrom_myPanel.getBounds());

  • search for next focusable, you can to play with get/setFocusedComponent() wrapped into invokeLater

  • most complex code is based on myComponent.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS), after Focus switched is required to switch notifiers betweens JComponents too

thanks, did it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.