This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I write program which as follows
Lots(90,900,9000) of small Draggable JPanels withing JPanel. For drag any small Jpanel i keep lot of area like (10000,70000) so i use JScrollpane with scroll bars.
But when i drag particular panel beyond visible area, i have to release it & move scrollbar where panel set.
So for solve this problem i think when small jpanel i pick visible rect also move along with it till boundries & scrollbars also move automatically, so when ever i drag panel, i can see easily where i am dragging it.
So in mouse Dragged event i write few lines as below:-
x1 & y1 are panel co-ordinates comes after calculation.
So by this i can see panel where i drag but it always on top left corner of screen but when i release the mouse, at that point that particular panel set. So partial problem solved.
Now how to keep panel with mouse cursor with scrollbar automatically moves where i drag it?
I not post whole code because its huge.
Millions saw the apple fall, but Newton asked why.
Thanks Michael Dunn & Rob Camick,
By your help i can complete my basic(basic is not right word but this program for show how concept works ) swing program.
Actually i use all techniques which i learn from coderanch in as bellow:-
small panels created by smallpanels.java
It called in show.java
so i can write mouse drag event at 2 places 1. smallpanels.java 2.show.java
At any location i use
When i drag smallpanel towards vertically -down or down rightside then it goes very fast at the end & i can not do opposite to it ie if i want to drag panel (which already below) towards up then
scrollbar not works as they work in basic swing program.!
So finally 2 results
1. Basic swing program finish with success.
2. Advanced & difficult swing program not finish as basic one.
Now i confuse what should i ask for get success? I am trying many R & D's by important 2 lines.
Thanks once again Michael Dunn,
As per your instruction & help i write in my program as follows
in smallpanel.java in mouse Dragged event, i write
& it works... So as my first query here work done...but in my mind some thoughts come as follows...
now question is when i drag small panel beyond(800,600)(if we consider resolution as 800,600) & drop anywhere then i start dragging it on visible screen then it should be roam freely, but it stick with scrollbar's so always when i dragg it at perticular, scrollbar moves at perticular direction, i mean as it freely roam in first screen(800,600), it should be consider now its second(800,600) or 3rd (800,600)....some thing same manner i saw in pc based games...
Or this thinking is wrong & i should stop here? I need thinking guidance...
Joined: Jun 13, 2009
You only need to set the autoscrolls property on the component added to the scrollpane.
Thanks Rob Camick,
but i set
What else should i do?
I see AOE game's, we can drag back panel here & there then we can drag small component visible area very easily without backpanel moving...when we need we move backpanel by dragging small component till limits, when not then it stop...
I not know how microsoft do that game or other games...
i am trying something like that with small panels...though i am not writing any game or its not necessary or compulsory to me...