>> I've been developing an application, where in one part of it i need to
>> drag Jbutton(s) to JPanel. First i used absolute values for JPanels
[quoted text clipped - 27 lines]
>
> BK
Hi,
Trying to be more pedantic now about the upper/lowercase. And being more
precise about the problem. No i didn't subclass JLayoutPane, not even
JLayeredPane.
What i'm trying to accomplish:
---------------------------
| --- --- --- |
| | | | | | | |
[quoted text clipped - 3 lines]
| -- -- -- -- -- -- |
| || || || || || || |
---------------------------
I need a few JPanels, (2-4) in upper 80% of view and a few draggable
JButtons in lower 20%. Now i tried this with JLayeredPane and GridLayout
where JPanels were in their own 80% and JButtons were in theirs 20 %.
This also didn't work, the layout was ok, but the layers didn't work. So
i did it with null layout and absolute values and it worked ok. I tried
to do my own LayoutManager which does the same as GridLayout. Idea was
to make simple LayoutManager that AFAIK doesn't kill the setLayer but to
no avail. (I implemented the Java.awt.LayoutManager2)
I'll copy the addLayoutComponent which is called after setLayer:
public void addLayoutComponent(Component comp, Object parameters)
//if Object is layoutObject
{ //add to vector, with parameters
if (parameters != null)
{
layoutObject my_params = (layoutObject)parameters;
int inner_container = my_params.getInnerContainer(); //to which
split i belong to
int orientation = my_params.getOrientation(); //my place in vector
LayoutVectorObject my_object;
my_object = new LayoutVectorObject(my_params, comp);
Vector my_vector = (Vector)vector_collection.get(inner_container);
if (orientation > 0)
{
my_vector.add(orientation,my_object);
}
else
{
my_vector.add(my_object);
}
}
}
After this the layoutContainer(Container parent) is called, it counts
and sets component to their places. No hassle there. The thing is as you
suspected this addLayoutComponent is called with null values, that's why
i use "if (parameters != null)" to handle them. Should it be handled
differently?
--quote--
So when you call setLayer, it might remove the component from itself and
add it again at a different index, and this will result in a remove and
add calls to the LayoutManager.
--qoute--
If this is the method of setLayer, should i just reorder the components
and "redraw" them myself? I really thought there was a more
sophisticated method for this. Also this might be the origin of the
problem, if setLayer just reorganises the components and redraws them,
and after that the LayoutManager redraws them again, in original order,
the setLayer is of no use. Well i'll check that now and report if that
was the case.
Thanks, Tomi
tompie - 28 Sep 2004 12:16 GMT
Hi all,
This problem seemed to solve itself... When i started to extend my
original JFrame which contained JLayeredPane all worked ok. There must
have been a scoping error on my part earlier(Well, i tried many
different solutions and did then other part of the program and got back
to this problem, rewrote the code and miracle had happened, it worked).
I'll propably also try if i can use GridLayout with this correctly. Let
you know then.
Thanks,
Tomi
Babu Kalakrishnan - 28 Sep 2004 17:07 GMT
>> Are you by any chance subclassing JLayoutPane and overriding any of
>> its methods (like add,remove etc) ?
> Trying to be more pedantic now about the upper/lowercase. And being more
> precise about the problem. No i didn't subclass JLayoutPane, not even
> JLayeredPane.
Sorry got LayoutManager and JLayeredPane mixed up - I meant
JLayeredPane not JLayoutPane :-)
Glad that the problem fixed itself, but just one clarification :
> --quote--
> So when you call setLayer, it might remove the component from itself and
[quoted text clipped - 9 lines]
> the setLayer is of no use. Well i'll check that now and report if that
> was the case.
You could actually do the reordering yourself - it should achieve the
same effect. But the only thing is that the reordering must be done in
the "components" list of the container - not that of the LayoutManager,
unless you plan to override the paintChildren method and do the painting
in a specific order. The LayoutManager is not even notified when a
paint() event takes place, so its inernal ordering of components
wouldn't be relevant. (The LayoutManager is supposed to finish its job
during the validation process, and its only job is to assign the bounds
of each child component - it will not get called while a drag is
occurring unless you invoke a revalidate() before the repaint() call).
BK