ResizableBorderComponent doesn't work

Hi all,
I am trying to use ResizableBorderComponent object to handle resizing of my_Component. The problem is that the resizing doesn’t work. Actually, the breakpoints in ResizableBorderComponent::mouseDown() and .mouseDragg() etc, don’t even get hit when I click/move the mouse
over the edge of my_Component().

Below are the relevant pieces of my code.

.h file
class my_Component : public Component,
public ComponentBoundsConstrainer

ComponentDragger dragger;
ResizableBorderComponent* border;



my_Component::my_Component(int x, int y, int X, int Y):
border(0) ,borderThickness(10) // it’s pretty thick :slight_smile:

addChildComponent (border =
new ResizableBorderComponent(this,this));

border->setBorderThickness (BorderSize (borderThickness));


Also, there are no other components on top of the border or on my_Component.

I would kindly appreciate any suggestions.

I have an equivalent code using of ResizableWindow, but I really
need to find out why the ResizableBorderComponent doesn’t work.


You’re missing the resized() function. Maybe you have it but forgot to post it here, but in case you haven’t done it:

The border needs to be set to the bounds of the container whenever it is resized. You have set it in the constructor, which is an obvious thing to try. However, without the resized function, as soon as the bounds of the component change, the bounds of the resizable border will be wrong (as they’ve not been updated).

The main reason this is broken without it is this: in the constructor of a component, the size is not yet set. You can see this in your code; you’ve created a ResizableBorderComponent, and then you’ve set its size - the constructor has been called, but you still need to set the size yourself afterwards. Thus, in yours, the constructor has been called (and your ResizableBorderComponent has been created and sized), but then - at the level which created your Component, the size is set - and the ResizableBorderComponent is not updated. You need to make sure this update happens by defining it in the Component’s ‘resized()’ function. You set its size in the same way you set it in the constructor:

my_Component::resized ()

Then hopefully all should be well.

You have to resize it in your resized() method so that it’s always got the same bounds as your window. Otherwise it’ll always just stay at its original size of (0, 0) and be unclickable.

ah - looks like you just beat me to it there, haydxn!

Thanks haydxn and jules for prompt response.

Using " border->setBounds(this->getBounds()); " is what I did originally but
I was getting this “Unhandled exception at 0x00523c04 in myHEllo.exe: 0xC0000005: Access violation reading location 0x0000001c.” when I did it,
so I thought I misunderstood the ResizableBorderComponent’s documentation.

The exception points to this line:
" const bool wasResized = (compW_ != w || compH_ != h);"
in Component::setBounds ()

Try “if (border) border->setBounds(this->getBounds);”, making sure you still have “My_Component() : border(0)”.
Whenever you get access violation, this means that you are reading/writing/executing code that is not accessible.

From the example you gave, if you are not sure your border is set (let’s say the one of the my_Component’s base call resized()), you shouldn’t use it.

Another tip : if the Access violation location address is 0x00000000, then it’s probably because you are using a null pointer. If it is small but not zero, then you are probably using a member from a null pointer (and the virtual method are stored few bytes after the pointer).

Good luck

You don’t want to copy the border’s bounds from that of the window, though - think about it: these are local co-ordinates, not global.

crumbs, yes, i was being lazy on my answer. personally i always do it like this:

resizer->setBounds (0,0,getWidth(),getHeight());

I just couldn’t be bothered typing it and was switched off! :slight_smile:

Thanks for you help guys :slight_smile:

“border->setBounds (0,0,getWidth(),getHeight());” does the job, but
now when I start dragging the horizontal borders (i.e. top or bottom) the window expands all the way to the edge of it’s parent and the edge being dragged disappears completely. When I try to drag the vertical borders (i.e. left or right edge), the entire window just disappears.

Now, all that my my_Component’s constructor does is this:
“my_Component::my_Component (int x, int y, int X, int Y)
: Component (T(“jaSelfContainer”)) ,
setBounds(x, y, X, Y);
addChildComponent (border=new ResizableBorderComponent (this, this));
border->setBorderThickness (BorderSize (borderThickness));

… and the only thing that both resize() and moved() do is :
"if (border) border->setBounds (0,0,getWidth(),getHeight()); "

I am just wondering what happened.
I suppose my issue was caused by some obvious mistake on my part and you just gave up on it or maybe it’s so hard that more time is needed to address it.

In either case, I am still interested if anybody has any suggestions
and I greatly appreciate your help so far . Thanks :slight_smile: