Question introduction:- I am trying to create simple swing program which has drag-able array of jpanels & jbuttons...(i create just 3 each)...
In simpleExample class
1 JFrame 1 Array of JPanels
1 Array of JLabels
1 Array of JButtons
1 Dragger class
Code as follows
There are 3 jpanels creates due to Array index 3 (0,1,2).
When you try to drag Jpanel which has low value of array index(0 or 1) over Jpanel which has high value of array index(1 or 2), then that low array indexed jpanel move from above to jpanel which has high value of array index.(in simple words, 0th panels can drag 'above' 1st or 2nd jpanel)
But when you try to opposite 2nd jpanel drag on 1st or 0th jpanel then it goes behind it same for if 1st jpanel try to drag on 0th it goes behind it.
First i thought this happened due to jpanel is container...so i create jbutton also..but same behavior by jbutton also.
Now Question:- Why that so...how to avoid it..i am trying to same behavior to all jpanels & jbuttons which created by array..no one should get backside to other when try to drag here & there.
I hope i try to simplest way to explain my question...
I know due to unknowing of few lines of code i can not do myself...but hope someone surely help ...
sorry of posting long code with long description...
Millions saw the apple fall, but Newton asked why.
If you understand, say "understand". If you don't understand, say "don't understand". But if you understand and say "don't understand". How do I understand that you understand? Understand!
Another way I've seen discussed in various threads: remove the component being dragged, add it to the glassPane for the duration of dragging, then return it to its normal place in the hierarchy.
There are no new questions, but there may be new answers.
Joined: Sep 11, 2007
Thanks Darryl Burke,
One way: setComponentZOrder(...)
by this one word...i realized that lot to learn in java basics...
Is this topic comes in basics or advanced java? this question is not major...
I try both ways...it might be take few days to understand & implement in my program..(due to slow learning/understanding...)
Craig Wood said as:-
The idea about using zOrder was to change the draggingComponents zOrder to zero in mousePressed as it is selected, before you start dragging it. This will keep it on top of any other children while you drag it.
As per stackoverflow i got basic code( 2 lines which i am searching)
By all 3 links i tried this in my code...
first i declare 2 integer in class simpleExample
private int myZorder=0;
Then in mousePressed event m....i write as follows
When i drag jpanel 1 over jpanel 0 it move from above...(previously not, it only move above on jpanel 2)..but now it works...but...
Post the full stack trace along with the line of code that threw the Exception and a few preceding lines.
here is that...
Actually i am facing 2 different problems...
1 for overlapping & 1 for default positioning of jpanels or jcomponents...(but this default positioning is not major for me..so i neglect it)
If that doesn't serve to identify the problem, you may need to create and post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.
The program posted in first post in this question is itself smallest code written by me...actually this question is regarding my questions
1 2 3 4
If you read all then it may be huge confusion regarding why,what,when,how etc...
So instead of more than 500 line code i posted only 139 line code which only java swing...
How can i do more SSCCE..i may be need example with reference or related to my code...
Read the API for setComponentZOrder(...) more carefully. This isn't right:
The first argument to the method can't be the same object on which the method is invoked -- and that wouldn't make any sense either.
IMO all you need is
Joined: Sep 11, 2007
Read the API for setComponentZOrder(...) more carefully.
Thanks for suggestion & that line which i missed to read & understand...
Now i have only 1 problem remain with my code which related to swing is avoid overlapping...
But i will ask separately...after try...