Drag and drop scrolling problem
Hi,
I have a problem with drag and drop in swing. Im hoping i can get this question answered without actually showing any code as i think its just theory. Basically I have a JScrollPane which is made up of a JTable, JLabel (Just a black separtor line) and JTable. The pane is quite small so if the number of files in say the bottom JTable is so much that the user needs to scroll up to drag and drop into the top JTable I start to encounter problems. Basically, it loses 'focus' when it hits the JLabel and no longer scrolls up so the user can never hit the top JPanel target.
Any ideas on how this can be resolved would be much appreciated as i have spent hours trying to fix this now.
Thanks,
Jack
Re: Drag and drop scrolling problem
Hmm... Well I haven't worked with JScrollPane much, but I'll try to offer some help.
First of all, I may suggest making your JScrollPane bigger. This is my simplest solution, but also a rather volatile solution...
If you don't like the first solution (I don't :P), then maybe you could try using a FocusListener (documentation here). You could add it to the JLabel that is causing the problem, and tell one of the JTables to request the focus whenever the JLabel retrieves it.
Maybe an alternate solution if you don't want to mess with FocusListeners: you could use two JScrollPanes, one for each JTable, instead of one. This way, both of your JTables would always be displayed no matter what, because they would each have their own individual JScrollPanes to navigate their contents.
Here are some links if you want to do some rummaging around of your own:
Focus Subsystem Tutorial
JScrollPane Documentation (Java 7)
JScrollPane Tutorial
Good luck on your project!